Your question is Sales by Month and User. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Edmunds wants a monthly view of sales performance by user for the current month and the two preceding calendar months. Write a PostgreSQL query that produces one row for every Edmunds user in each of those three months, including users with no sales.
CURRENT_DATE.LAG to calculate the prior month's sales amount and sales change.| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Edmunds user identifier |
| user_name | VARCHAR(100) | User display name |
| Column | Type | Description |
|---|---|---|
| sales_idPK | INTEGER | Unique sale identifier |
| user_id | INTEGER | User who made the sale |
| sales_date | DATE | Date the sale occurred |
| sales_amount | NUMERIC(12,2) | Sale amount, including refunds |
| sales_quantity | INTEGER | Number of units in the sale |