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.
Requirements
- Return every customer, including customers with no qualifying orders.
- Include orders from
CURRENT_DATE - INTERVAL '1 year' through CURRENT_DATE, inclusive.
- Calculate the average of
order_amount, ignoring NULL amounts, and round the result to two decimal places.
- Sort the output by
customer_id in ascending order.
Output details
- Return columns
customer_id, customer_name, and average_order_value in that order.
- Treat customers without any non-NULL qualifying
order_amount as having a NULL average_order_value.
- Treat
DATE '2026-08-29' as today's date.