Last updated
Use window functions and aggregations to analyze monthly sales performance, AOV trends, and returning customer behavior.
Use window functions and aggregations to analyze monthly sales performance, AOV trends, and returning customer behavior.
Your dataset contains two tables from an e-commerce platform: 1. An orders table with order_id, customer_id, order_date, and status for each order 2. An order_items table with item_id, order_id, quantity, and line_amount for each line item in the order
| Column | Type | Key / Notes |
|---|---|---|
| order_id | INT | PK |
| customer_id | INT | FK |
| order_date | DATE | |
| status | VARCHAR(20) |
| Column | Type | Key / Notes |
|---|---|---|
| item_id | INT | PK |
| order_id | INT | FK |
| quantity | INT | |
| line_amount | DECIMAL(10,2) |
orders — sample
| order_id | customer_id | order_date | status |
|---|---|---|---|
| 1 | 101 | 2024-01-05 | Completed |
| 2 | 102 | 2024-01-12 | Completed |
| 3 | 103 | 2024-01-18 | Cancelled |
| 4 | 104 | 2024-01-25 | Completed |
| 5 | 105 | 2024-02-03 | Completed |
| 6 | 106 | 2024-02-14 | Completed |
| 7 | 107 | 2024-03-02 | Completed |
| 8 | 108 | 2024-03-19 | Completed |
| 9 | 109 | 2024-04-08 | Completed |
| 10 | 110 | 2024-04-22 | Completed |
order_items — sample
| item_id | order_id | quantity | line_amount |
|---|---|---|---|
| 1 | 1 | 3 | 3,600.00 |
| 2 | 1 | 2 | 2,400.00 |
| 3 | 2 | 5 | 6,000.00 |
| 4 | 3 | 1 | 1,100.00 |
| 5 | 4 | 4 | 4,800.00 |
| 6 | 5 | 2 | 2,500.00 |
| 7 | 6 | 3 | 3,100.00 |
| 8 | 6 | 1 | 900.00 |
| 9 | 7 | 6 | 7,200.00 |
| 10 | 8 | 3 | 4,500.00 |
This drill has two tasks: 1. Monthly Sales Trend — How have total quantity sold and revenue changed month-over-month in the last 12 months? Your result table should have: month_year, revenue, MoM_rev, qty, MoM_qty_sold. 2. Average Order Value (AOV) Trend — How is AOV (revenue ÷ number of orders) trending by month? Your result table should have: month_year, AOV, MoM_AOV.
Your output should look like this (partial example):
| month_year | revenue | MoM_rev | qty | MoM_qty_sold |
|---|---|---|---|---|
| January, 2024 | 124,500 | NULL | 1,840 | NULL |
| February, 2024 | 118,200 | -5.06% | 1,710 | -7.07% |
| … | … | … | … | … |