-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-advanced-exercises.sql
More file actions
25 lines (15 loc) · 979 Bytes
/
Copy path03-advanced-exercises.sql
File metadata and controls
25 lines (15 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- Exercise 03: Advanced SQL
-- Write your answers below each question.
-- 1. Build a monthly sales CTE and show a running total.
-- 2. Rank customers by total sales within each region using a window function.
-- 3. Find the top 3 products by profit in each category.
-- 4. Use LAG to compare each order date to the previous order date per customer.
-- 5. Calculate percent of total sales by region using a window function.
-- 6. Find the best sales month in each year.
-- 7. Compare weekend and weekday sales using periode.
-- 8. For each region, return the month with the highest profit and include the profit rank.
-- 9. Build a customer summary CTE that shows total sales, total profit, total orders,
-- and average days between first and last order for each customer.
-- 10. Create a query that compares each month's sales to the previous month and returns:
-- year, month, total sales, previous month sales, sales difference,
-- and growth percentage.