You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

How-to-code-summary-queries.sql 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. -- Exercise 1
  2. SELECT COUNT(order_id) AS order_count, SUM(tax_amount) AS tax_total
  3. FROM orders;
  4. -- Exercise 2
  5. SELECT category_name, COUNT(product_name) AS product_count, sum(list_price)
  6. FROM categories c JOIN products p
  7. ON c.category_id = p.category_id.
  8. ORDER BY category_name ASC;
  9. -- Exercise 3
  10. SELECT email_adress,SUM(item_price*quantity) AS item_price_total, SUM(discount_amount*quantity) AS discount_amount
  11. FROM administrators c JOIN order_items l
  12. ON c.admin_id = l.admin_id
  13. ORDER BY item_price DESC;
  14. -- Exercise 4
  15. SELECT email_adress, COUNT(order_id) AS order_count, SUM((ship_amount-tax_amount)*quantity) AS order_total
  16. FROM administrators c JOIN orders o
  17. ON c.admin_id_id = o.admin_id
  18. WHERE admin_id > 1
  19. ORDER BY SUM(list_price) DESC;
  20. -- Exercise 5
  21. SELECT email_adress, COUNT(order_id) AS order_count, SUM((ship_amount-tax_amount)*quantity) AS order_total
  22. FROM administrators c JOIN orders o
  23. ON c.admin_id_id = o.admin_id
  24. WHERE order_id >= 400
  25. ORDER BY SUM(list_price) DESC;
  26. -- Exercise 6
  27. -- Exercise 7
  28. SELECT email_adress, sum(product_id) AS number_of_products
  29. FROM administrators a JOIN products p
  30. ON a.admin_id = p.admin_id
  31. ORDER BY admin_id ASC;