Guest User

Untitled

a guest
Jul 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. Questions:
  2. 01. Find the sales in terms of total dollars for all orders in each year, ordered from greatest to least. Do you notice any trends in the yearly sales totals?
  3. 02. Which month did Parch & Posey have the greatest sales in terms of total dollars? Are all months evenly represented by the dataset?
  4. 03. Which year did Parch & Posey have the greatest sales in terms of total number of orders? Are all years evenly represented by the dataset?
  5. 04. Which month did Parch & Posey have the greatest sales in terms of total number of orders? Are all months evenly represented by the dataset?
  6. 05. In which month of which year did Walmart spend the most on gloss paper in terms of dollars?
  7.  
  8. Question 01.
  9. SELECT DATE_PART('year', o.occurred_at) AS year, SUM(total_amt_usd) AS total
  10. FROM orders o
  11. GROUP BY year
  12. ORDER BY total DESC
  13.  
  14. Question 02.
  15. SELECT DATE_PART('month', o.occurred_at) AS month, SUM(total_amt_usd) AS total
  16. FROM orders o
  17. GROUP BY month
  18. ORDER BY total DESC
  19.  
  20. if we look closer, 2013 and 2017 have only one month, to gather more precise data we ensure to look after 2013.
  21. SELECT DATE_PART('month', o.occurred_at) AS month, SUM(total_amt_usd) AS total
  22. FROM orders o
  23. WHERE o.occurred_at BETWEEN '2014-01-01' AND '2017-01-01'
  24. GROUP BY month
  25. ORDER BY total DESC
  26.  
  27. Question 03.
  28. SELECT DATE_PART('year', o.occurred_at) AS year, COUNT(*) AS orders
  29. FROM orders o
  30. GROUP BY year
  31. ORDER BY orders DESC
  32.  
  33. Question 04.
  34. SELECT DATE_PART('month', o.occurred_at) AS month, COUNT(*) AS orders
  35. FROM orders o
  36. WHERE o.occurred_at BETWEEN '2014-01-01' AND '2017-01-01'
  37. GROUP BY month
  38. ORDER BY orders DESC
  39.  
  40. Question 05.
  41. SELECT DATE_PART('year', o.occurred_at) AS year, DATE_PART('month', o.occurred_at) AS month, SUM(gloss_amt_usd) AS orders
  42. FROM orders o
  43. JOIN accounts a
  44. ON o.account_id = a.id
  45. WHERE a.name = 'Walmart'
  46. GROUP BY year, month
  47. ORDER BY orders DESC
  48. LIMIT(1);
Add Comment
Please, Sign In to add comment