Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 4. 13134, 13134, 38, Clerk
- 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.
- 6. C
- 7. SELECT (UnitPrice * Quantity) AS LineItemSum,
- CASE
- WHEN (GROUPING(EmployeeID) = 1) THEN 9999
- ELSE (EmployeeID)
- END AS EmployeeID,
- CASE
- WHEN (GROUPING(ShipCity) = 1) THEN '*All*'
- ELSE (ShipCity)
- END AS ShipCity
- FROM "Order Details" INNER JOIN Orders
- ON "Order Details".OrderID = Orders.OrderID
- GROUP BY (UnitPrice * Quantity), EmployeeID, ShipCity WITH CUBE
- 8. SELECT COUNT(OrderID) as 'Count', EmployeeID, Max(Freight) as 'Max Freight'
- FROM Orders
- Group By EmployeeID
- HAVING MAX(Freight) < 600
- 9. SELECT Max(HireDate) AS LatestHireDate, Min(HireDate) AS EarliestHireDate
- FROM Employees
- 10. SELECT FirstName + ' ' + LEFT(LastName, 1) + '.' AS Contact,
- RIGHT(HomePhone,8) AS Phone
- FROM Employees
- ORDER BY Contact
- 11 - 14 brad put in discord i think
- 15. The join columns are invalid
- 16. SELECT country, COUNT(*) AS [customer cnt]
- FROM Customers
- GROUP BY country
- HAVING COUNT(*) > 5
- 17. INSERT INTO Shippers (CompanyName, Phone) VALUES ('ParcelForce', '0800-22446')
- 18.
- SELECT VendorName, AccountDescription, COUNT(*) AS LineItemCount
- , SUM(InvoiceLineItemAmount) AS LineItemSum
- FROM Vendors
- JOIN Invoices ON Vendors.VendorID = Invoices.VendorID
- JOIN InvoiceLineItems ON Invoices.InvoiceID = InvoiceLineItems.InvoiceID
- JOIN GLAccounts ON InvoiceLineItems.AccountNo = GLAccounts.AccountNo
- GROUP BY VendorName, AccountDescription
- ORDER BY VendorName, AccountDescription;
- 19.
- SELECT VendorID, InvoiceDate, InvoiceTotal,
- SUM(InvoiceTotal) OVER (PARTITION BY VendorID) AS VendorTotal,
- COUNT(InvoiceTotal) OVER (PARTITION BY VendorID) AS VendorCount,
- AVG(InvoiceTotal) OVER (PARTITION BY VendorID) AS VendorAvg
- FROM Invoices
- 20.
- SELECT DISTINCT VendorName, COUNT (*) AS NumberofAccounts
- FROM Vendors JOIN InvoiceLineItems ON Vendors.DefaultAccountNo = InvoiceLineItems.AccountNo
- GROUP BY VendorName
- HAVING COUNT (*) > 1
- 21. SELECT VendorID, SUM(PaymentTotal) AS PaymentSum
- FROM Invoices
- GROUP BY VendorID;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement