Your question is Running Total by Product. Start with the requirements and the three 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.
EPAM Systems wants a daily revenue view for products sold through its digital services portfolio. Write a PostgreSQL query that reports revenue by product and date for the reporting period from 2025-01-01 through 2025-01-04.
daily_revenue as quantity * unit_price, counting only sales with status = 'completed'. Treat missing revenue as zero.running_total separately for each product, ordered chronologically.daily_change as the difference between the current day's revenue and the previous day's revenue for that product. Return NULL for the first date.| Column | Type | Description |
|---|---|---|
| category_idPK | INT | Category identifier |
| category_name | VARCHAR(100) | Category name |
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Product identifier |
| product_name | VARCHAR(150) | Product name |
| category_id | INT | References categories.category_id |
| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Sale identifier |
| product_id | INT | References products.product_id |
| sale_date | DATE | Date on which the sale occurred |
| quantity | INT | Number of units sold |
| unit_price | NUMERIC(10,2) | Price per unit |
| status | VARCHAR(20) | Sale processing status |