Advertisement
RazorBlade57

hw#6

Oct 9th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.31 KB | None | 0 0
  1. -- Problem #1
  2. SELECT
  3.     COUNT(order_id),
  4.     SUM(tax_amount)
  5. FROM orders;
  6.  
  7. -- Problem #2
  8. SELECT
  9.     category_name,
  10.     COUNT(*) AS product_count,
  11.     MAX(list_Price) AS most_expensive_product
  12. FROM categories
  13. JOIN products ON products.category_id = categories.category_id
  14. GROUP BY category_name;
  15.  
  16. -- Problem #3
  17. SELECT
  18.     email_address,
  19.     SUM(item_price * quantity),
  20.     SUM(discount_amount * quantity)
  21. FROM customers
  22. JOIN orders ON customers.customer_id = orders.customer_id
  23. JOIN order_items ON orders.order_id = order_items.order_id
  24. GROUP BY email_address
  25. ORDER BY item_price DESC;
  26.  
  27. -- Problem #4
  28. SELECT
  29.     email_address,
  30.     COUNT(item_id),
  31.     (item_price - discount_amount) * quantity
  32. FROM customers
  33. JOIN orders ON orders.customer_id = customers.customer_id
  34. JOIN order_items ON orders.order_id = order_items.order_id
  35. GROUP BY email_address
  36. HAVING COUNT(item_id) > 1
  37. ORDER BY ((item_price - discount_amount) * quantity) DESC;
  38.  
  39. -- Problem #5
  40. SELECT
  41.     email_address,
  42.     COUNT(item_id),
  43.     (item_price - discount_amount) * quantity
  44. FROM customers
  45. JOIN orders ON orders.customer_id = customers.customer_id
  46. JOIN order_items ON orders.order_id = order_items.order_id AND item_price >400
  47. GROUP BY email_address
  48. HAVING COUNT(item_id) > 1
  49. ORDER BY ((item_price - discount_amount) * quantity) DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement