Your question is Average Order Value Query. 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.
Insight Global's reporting team needs a customer-level view of spending activity. Write a PostgreSQL query that calculates the average order value for every customer during the rolling year ending on the current date. For the sample data, assume the current date is 2026-08-29.
CURRENT_DATE - INTERVAL '1 year' through CURRENT_DATE, inclusive.order_amount, ignoring NULL amounts, and round the result to two decimal places.customer_id in ascending order.| Column | Type | Description |
|---|---|---|
| customer_idPK | INTEGER | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| Column | Type | Description |
|---|---|---|
| order_idPK | INTEGER | Unique order identifier |
| customer_id | INTEGER | References customers.customer_id |
| order_date | DATE | Date the order was placed |
| order_amount | NUMERIC(10,2) | Order value |