Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. use Northwind
  2. --11
  3. select lastname, SUM(quantity)
  4. from Employees e join Orders o on
  5. e.EmployeeID=o.EmployeeID join [Order Details]
  6. od on o.OrderID=od.OrderID join Products p
  7. on od.ProductID=p.ProductID
  8. where ProductName='chai' and
  9. YEAR(OrderDate)=1997
  10. group by LastName
  11.  
  12. select MONTH(orderdate), SUM(od.unitprice*quantity)
  13. from orders o join [Order Details] od on
  14. o.OrderID=od.OrderID join Products p on
  15. od.ProductID=p.ProductID join Categories c on
  16. p.CategoryID=c.CategoryID
  17. where YEAR(OrderDate)=1997 and
  18. CategoryName='Seafood'
  19. group by MONTH(OrderDate)
  20.  
  21. select country, SUM(unitprice*quantity)
  22. from Customers c join Orders o on
  23. c.CustomerID=o.CustomerID join [Order Details]
  24. od on o.OrderID=od.OrderID
  25. where YEAR(OrderDate)=1997
  26. group by Country
  27.  
  28. select o.*
  29. from Orders o join [Order Details] od on
  30. o.OrderID=od.OrderID join Products p on
  31. od.ProductID=p.ProductID join Suppliers s on
  32. p.SupplierID=s.SupplierID
  33. where YEAR(OrderDate)=1996 and s.CompanyName
  34. like '%ltd.%'
  35.  
  36. --15
  37. --16
  38. select AVG(od.unitprice)
  39. from [Order Details] od join orders o
  40. on od.orderid=o.orderid
  41. where OrderDate between '1996-01-01' and '1996-03-31'
  42.  
  43. select MIN(unitprice)
  44. from Products p join Suppliers s on
  45. p.SupplierID=s.SupplierID
  46. where Country='usa'
  47.  
  48. select COUNT(*)
  49. from [Order Details] od join Products p on
  50. od.ProductID=p.ProductID
  51. where ProductName='chef anton''s gumbo mix'
  52.  
  53. select AVG(od.unitprice)
  54. from [Order Details] od join orders o
  55. on od.OrderID=o.OrderID
  56. where OrderDate between '1997-04-01' and '1997-06-30'
  57.  
  58. --20
  59. select productname, companyname, categoryname
  60. from Categories c join Products p
  61. on c.CategoryID=p.CategoryID join Suppliers s
  62. on p.SupplierID=s.SupplierID
  63. where CompanyName like 'Pavlova%'
  64.  
  65. select c.*, customertypeid
  66. from Customers c join CustomerCustomerDemo ccd
  67. on c.CustomerID=ccd.CustomerID
  68.  
  69. select productname
  70. from products p join Suppliers s on
  71. p.SupplierID=s.SupplierID
  72. where Country='Japan'
  73.  
  74. select distinct c.city
  75. from Customers c join Orders o on
  76. c.CustomerID=o.CustomerID join Employees e on
  77. o.EmployeeID=e.EmployeeID
  78. where LastName='King'
  79.  
  80. select productname, p.unitprice as 'cena aktualna', od.unitprice as 'cena na zamowieniu'
  81. from Categories c join Products p on c.CategoryID=p.CategoryID join [Order Details] od on p.ProductID=od.ProductID
  82. where CategoryName='beverages'
  83. order by 3 desc
  84.  
  85. select distinct productname, p.unitprice as 'cena aktualna', od.unitprice as 'cena na zamowieniu'
  86. from Categories c join Products p on c.CategoryID=p.CategoryID join [Order Details] od on p.ProductID=od.ProductID
  87. where CategoryName='beverages'
  88. and p.UnitPrice<>od.UnitPrice
  89. order by 3 desc
  90.  
  91. select companyname, orderdate, requireddate
  92. as 'czas wymagany'
  93. from customers c join orders o on
  94. c.customerid=o.CustomerID
  95. where ShippedDate<=RequiredDate
  96.  
  97. select companyname, orderdate,
  98. CAST(shippeddate-requireddate as int), lastname
  99. from Customers c join Orders o on
  100. c.CustomerID=o.CustomerID join Employees e on
  101. o.EmployeeID=e.EmployeeID
  102. where ShippedDate>RequiredDate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement