Pada Pembahasan kali ini, saya akan membahas tentang Fungsi WHERE dan In di Pemrogaman SQL. Langsung saja pembahasanya...
use Northwind
select *
from Employees
where Country = 'UK'
use Northwind
--
select *
from [Orders]
where TitleOfCourtesy = 'Mr.' and Country = 'UK'
-- menampilkan order yang di layani oleh employee nomer satu pada waktu > 15
select OrderID,CustomerID,EmployeeID,DATEDIFF(YY,OrderDate,GETDATE()) as waktu
from Orders
where EmployeeID = 1 and DATEDIFF(YY,OrderDate,GETDATE()) > 15
--tampilkan order yang tujuanya prancis atau brazil dan di layani oleh employeeID 1 dan pemesan selai WELLI
select *
from Orders
where (ShipCountry = 'France' or ShipCountry = 'Brazil') and EmployeeID = 1 and CustomerID <> 'WELLI'
--tampilkan order yang di layani emplooyee no 1 atau 2 oleh customer bonap atau lamaii
select *
from Orders
where EmployeeID in(1,2) and (CustomerID = 'BONAP' or CustomerID = 'LAMAI')
--tampilkan order yang tidak di layani emplooyee no 1 atau 2 oleh customer bonap atau lamaii
select *
from Orders
where EmployeeID not in (1,2) and (CustomerID = 'BONAP' or CustomerID = 'LAMAI')
use Northwind
select *
from Employees
where Country = 'UK'
use Northwind
--
select *
from [Orders]
where TitleOfCourtesy = 'Mr.' and Country = 'UK'
-- menampilkan order yang di layani oleh employee nomer satu pada waktu > 15
select OrderID,CustomerID,EmployeeID,DATEDIFF(YY,OrderDate,GETDATE()) as waktu
from Orders
where EmployeeID = 1 and DATEDIFF(YY,OrderDate,GETDATE()) > 15
--tampilkan order yang tujuanya prancis atau brazil dan di layani oleh employeeID 1 dan pemesan selai WELLI
select *
from Orders
where (ShipCountry = 'France' or ShipCountry = 'Brazil') and EmployeeID = 1 and CustomerID <> 'WELLI'
--tampilkan order yang di layani emplooyee no 1 atau 2 oleh customer bonap atau lamaii
select *
from Orders
where EmployeeID in(1,2) and (CustomerID = 'BONAP' or CustomerID = 'LAMAI')
--tampilkan order yang tidak di layani emplooyee no 1 atau 2 oleh customer bonap atau lamaii
select *
from Orders
where EmployeeID not in (1,2) and (CustomerID = 'BONAP' or CustomerID = 'LAMAI')
0 komentar:
Posting Komentar