--1. Hiển thị thông tin về hóa đơn có mã ‘10248’, bao gồm: OrderID, --OrderDate, CustomerID, EmployeeID, ProductID, Quantity, Unitprice, --Discount. SELECT o.OrderID, OrderDate, CustomerID, EmployeeID, ProductID, Quantity, Unitprice, Discount FROM Orders o join [Order Details] od on o.OrderID=od.OrderID WHERE o.OrderID = '10248' --2. Liệt kê các khách hàng có lập hóa đơn trong tháng 7/1997 và 9/1997. --Thông tin gồm CustomerID, CompanyName, Address, OrderID, Orderdate --. Được sắp xếp theo CustomerID, cùng CustomerID thì sắp xếp --theo OrderDate giảm dần. SELECT c.CustomerID, CompanyName, Address, OrderID, OrderDate FROM Customers c join Orders o on c.CustomerID=o.CustomerID WHERE (month(OrderDate)=7 and year(OrderDate)=1997) and (month(OrderDate)=9 and year(OrderDate)=1997) Order by c.CustomerID, o.CustomerID, OrderDate desc --3. Liệt kê danh sách các mặt hàng xuất bán vào ngày 19/7/1996. Thông tin --gồm : ProductID, ProductName, OrderID, OrderDate, Quantity. SELECT p.ProductID, ProductName, o.OrderID, OrderDate, Quantity FROM Orders o join [Order Details] od on o.OrderID=od.OrderID join Products p on p.ProductID=od.ProductID WHERE OrderDate='1996-07-19' --4. Liệt kê danh sách các mặt hàng từ nhà cung cấp (supplier) có mã 1,3,6 và --đã xuất bán trong quý 2 năm 1997. Thông tin gồm : ProductID, --ProductName, SupplierID, OrderID, Quantity. Được sắp xếp theo mã --nhà cung cấp (SupplierID), cùng mã nhà cung cấp thì sắp xếp theo --ProductID. SELECT p.ProductID, ProductName, s.SupplierID, o.OrderID, Quantity, OrderDate FROM Suppliers s join Products p on s.SupplierID=p.SupplierID join [Order Details] od on p.ProductID=od.ProductID join Orders o on od.OrderID=o.OrderID WHERE (s.SupplierID = 1 or s.SupplierID = 3 or s.SupplierID = 6) and datepart(QUARTER,OrderDate)=2 and year(OrderDate)=1997 --5. Liệt kê danh sách các mặt hàng có đơn giá bán bằng đơn giá mua. SELECT * FROM Products p join [Order Details] od on p.UnitPrice=od.UnitPrice WHERE p.UnitPrice=od.UnitPrice --6. Danh sách các mặt hàng bán trong ngày thứ 7 và chủ nhật của tháng 12 --năm 1996, thông tin gồm ProductID, ProductName, OrderID, OrderDate, --CustomerID, Unitprice, Quantity, ToTal= Quantity*UnitPrice. Được sắp --xếp theo ProductID, cùng ProductID thì sắp xếp theo Quantity giảm dần. SELECT p.ProductID, ProductName, o.OrderID, OrderDate, CustomerID, p.Unitprice, Quantity, Quantity*p.UnitPrice AS Total FROM Products p join [Order Details] od on p.ProductID=od.ProductID and p.UnitPrice=od.UnitPrice join Orders o on o.OrderID=od.OrderID WHERE datepart(WEEKDAY,OrderDate)=6 or datepart(WEEKDAY,OrderDate)=7 and month(OrderDate)=12 and year(OrderDate)=1996 Order by ProductID, Quantity desc --7. Liệt kê danh sách các nhân viên đã lập hóa đơn trong tháng 7 của năm --1996. Thông tin gồm : EmployeeID, EmployeeName, OrderID, --Orderdate. SELECT e.EmployeeID, LastName+' '+Firstname AS EmployeeName, OrderID, Orderdate FROM Employees e join Orders o on e.EmployeeID=o.EmployeeID WHERE month(OrderDate)=7 and year(OrderDate)=1996 --8. Liệt kê danh sách các hóa đơn do nhân viên có Lastname là ‘Fuller’ lập. --Thông tin gồm : OrderID, Orderdate, ProductID, Quantity, Unitprice. SELECT o.OrderID, Orderdate, ProductID, Quantity, Unitprice FROM [Order Details] od join Orders o on od.OrderID=o.OrderID, Employees WHERE LastName='Fuller' --9. Liệt kê chi tiết bán hàng của mỗi nhân viên theo từng hóa đơn trong năm --1996. Thông tin gồm: EmployeeID, EmployName, OrderID, Orderdate, --ProductID, quantity, unitprice, ToTalLine=quantity*unitprice. SELECT e.EmployeeID, LastName+' '+Firstname AS EmployName, od.OrderID, Orderdate, ProductID, quantity, unitprice, Quantity*Unitprice AS ToTalLine FROM Employees e join Orders o on e.EmployeeID=o.EmployeeID join [Order Details] od on od.OrderID=o.OrderID WHERE year() --10.Danh sách các đơn hàng sẽ được giao trong các thứ 7 của tháng 12 năm --1996. --11.Liệt kê danh sách các nhân viên chưa lập hóa đơn (dùng LEFT --JOIN/RIGHT JOIN). --12.Liệt kê danh sách các sản phẩm chưa bán được (dùng LEFT --JOIN/RIGHT JOIN). --13.Liệt kê danh sách các khách hàng chưa mua hàng lần nào (dùng LEFT --JOIN/RIGHT JOIN).