Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. 4. 13134, 13134, 38, Clerk
  2. 5. B returned deptID 38 clerks because it takes each result separately. Naughton makes over $13,000, but Abraham makes less than $13,000. Instead of seeing them as a group, B saw them individually because the WHERE clause doesn't use GROUP BY. C saw them together because it has a HAVING clause. The HAVING clause runs the results through as a group and only returns groups in which all the data fulfills the query parameters.
  3. 6. C
  4. 7. SELECT (UnitPrice * Quantity) AS LineItemSum,
  5. CASE
  6. WHEN (GROUPING(EmployeeID) = 1) THEN 9999
  7. ELSE (EmployeeID)
  8. END AS EmployeeID,
  9. CASE
  10. WHEN (GROUPING(ShipCity) = 1) THEN '*All*'
  11. ELSE (ShipCity)
  12. END AS ShipCity
  13. FROM "Order Details" INNER JOIN Orders
  14. ON "Order Details".OrderID = Orders.OrderID
  15. GROUP BY (UnitPrice * Quantity), EmployeeID, ShipCity WITH CUBE
  16. 8. SELECT COUNT(OrderID) as 'Count', EmployeeID, Max(Freight) as 'Max Freight'
  17. FROM Orders
  18. Group By EmployeeID
  19. HAVING MAX(Freight) < 600
  20. 9. SELECT Max(HireDate) AS LatestHireDate, Min(HireDate) AS EarliestHireDate
  21. FROM Employees
  22. 10. SELECT FirstName + ' ' + LEFT(LastName, 1) + '.' AS Contact,
  23. RIGHT(HomePhone,8) AS Phone
  24. FROM Employees
  25. ORDER BY Contact
  26. 11 - 14 brad put in discord i think
  27. 15. The join columns are invalid
  28. 16. SELECT country, COUNT(*) AS [customer cnt]
  29.  
  30. FROM Customers
  31.  
  32. GROUP BY country
  33.  
  34. HAVING COUNT(*) > 5
  35. 17. INSERT INTO Shippers (CompanyName, Phone) VALUES ('ParcelForce', '0800-22446')
  36. 18.
  37. SELECT VendorName, AccountDescription, COUNT(*) AS LineItemCount
  38. , SUM(InvoiceLineItemAmount) AS LineItemSum
  39. FROM Vendors
  40. JOIN Invoices ON Vendors.VendorID = Invoices.VendorID
  41. JOIN InvoiceLineItems ON Invoices.InvoiceID = InvoiceLineItems.InvoiceID
  42. JOIN GLAccounts ON InvoiceLineItems.AccountNo = GLAccounts.AccountNo
  43. GROUP BY VendorName, AccountDescription
  44. ORDER BY VendorName, AccountDescription;
  45. 19.
  46. SELECT VendorID, InvoiceDate, InvoiceTotal,
  47. SUM(InvoiceTotal) OVER (PARTITION BY VendorID) AS VendorTotal,
  48. COUNT(InvoiceTotal) OVER (PARTITION BY VendorID) AS VendorCount,
  49. AVG(InvoiceTotal) OVER (PARTITION BY VendorID) AS VendorAvg
  50. FROM Invoices
  51. 20.
  52. SELECT DISTINCT VendorName, COUNT (*) AS NumberofAccounts
  53. FROM Vendors JOIN InvoiceLineItems ON Vendors.DefaultAccountNo = InvoiceLineItems.AccountNo
  54. GROUP BY VendorName
  55. HAVING COUNT (*) > 1
  56. 21. SELECT VendorID, SUM(PaymentTotal) AS PaymentSum
  57.  
  58. FROM Invoices
  59.  
  60. GROUP BY VendorID;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement