Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Questions:
- 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?
- 02. Which month did Parch & Posey have the greatest sales in terms of total dollars? Are all months evenly represented by the dataset?
- 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?
- 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?
- 05. In which month of which year did Walmart spend the most on gloss paper in terms of dollars?
- Question 01.
- SELECT DATE_PART('year', o.occurred_at) AS year, SUM(total_amt_usd) AS total
- FROM orders o
- GROUP BY year
- ORDER BY total DESC
- Question 02.
- SELECT DATE_PART('month', o.occurred_at) AS month, SUM(total_amt_usd) AS total
- FROM orders o
- GROUP BY month
- ORDER BY total DESC
- if we look closer, 2013 and 2017 have only one month, to gather more precise data we ensure to look after 2013.
- SELECT DATE_PART('month', o.occurred_at) AS month, SUM(total_amt_usd) AS total
- FROM orders o
- WHERE o.occurred_at BETWEEN '2014-01-01' AND '2017-01-01'
- GROUP BY month
- ORDER BY total DESC
- Question 03.
- SELECT DATE_PART('year', o.occurred_at) AS year, COUNT(*) AS orders
- FROM orders o
- GROUP BY year
- ORDER BY orders DESC
- Question 04.
- SELECT DATE_PART('month', o.occurred_at) AS month, COUNT(*) AS orders
- FROM orders o
- WHERE o.occurred_at BETWEEN '2014-01-01' AND '2017-01-01'
- GROUP BY month
- ORDER BY orders DESC
- Question 05.
- SELECT DATE_PART('year', o.occurred_at) AS year, DATE_PART('month', o.occurred_at) AS month, SUM(gloss_amt_usd) AS orders
- FROM orders o
- JOIN accounts a
- ON o.account_id = a.id
- WHERE a.name = 'Walmart'
- GROUP BY year, month
- ORDER BY orders DESC
- LIMIT(1);
Add Comment
Please, Sign In to add comment