יום שלישי, 5 בדצמבר 2017

תרגול קליל SQL

תרגול SQL:



אפשרות א': הורדה
אפשרות ב': קריאה ישירה-






פתרונות (של דביר):




select substring(FirstName,1,3),FirstName--ממקום אחד הביא 3 תווים
from Employees


--9 //5.12.17
select FirstName,LastName
from Employees
where EmployeeID=3

--10
select ProductID,ProductName,UnitPrice
from Products
where unitprice > 20
order by UnitPrice desc

--11
select FirstName+' '+LastName +CONVERT(char(3),ReportsTo)
from Employees
where EmployeeID=8

--12
select FirstName+''+LastName as[Name]
from Employees
where City = 'london'

--13
select *
from Products
where UnitPrice between 50 and 100


--14
select ProductName,UnitPrice
from Products
where UnitPrice between 21.35 and 43.9
order by UnitPrice asc


--15
select EmployeeID,LastName,[HireDate]
from Employees 
where city in ('LONDON' , 'TACOMA')


--16
select EmployeeID,LastName
from Employees
where EmployeeID in (1,2,5)

--17
select EmployeeID,LastName
from Employees
where EmployeeID not in (1,2,5)


--18
select P.ProductID,P.ProductName,C.CategoryID
from Products as P join Categories as C
on P.CategoryID = C.CategoryID
where C.CategoryID not in (1,2,7)
order by CategoryID asc


--19
select [LastName],Region
from Employees
where Region is null

--20
select top 3 * 
from  Products

--21
select OrderID,[OrderDate],[RequiredDate]
from orders
where RequiredDate>'1996-10-1'

--22
select EmployeeID,LastName
from Employees
where ReportsTo is not null

--23
select *
 from Categories
 where CategoryName like '%s%'


 --24
 select*
 from Customers
 where CompanyName like'%a'


 --25
 select OrderID,CustomerID
 from Orders
 where Orderdate  between '1997-4-1' and '1997-5-1'
 order by OrderDate asc , CustomerID desc

 --26
 select CustomerID,[Country],[CompanyName],[Phone],[Region]
 from Customers
 where [Country] like  'G%' or [Country] like 'M%' or [Country] like 'F%' and region is null

 --27
 select EmployeeID, FirstName+'  '+LastName as[Full Name],BirthDate,[Country]
 from Employees
 where LastName like '%D%' or LastName like'%K%' and BirthDate =1963 

 --28
 select *
 from Products
 where UnitPrice>30 and  SupplierID in (1 , 3)


 --29
 select top 25 percent *
 from Employees
 where EmployeeID >3



בהצלחה!


2 תגובות:

  1. אם אתה רוצה את התשובות של השאלות הנ"ל אני אשמח להביא לך אותם (שהתשובות שלי יככבו אצלך)

    השבמחק