Skip to main content
All Problems
hard0% acceptance

Recursive CTE: Order Value Tiers with Running Stats

Use a recursive CTE to generate order value ranges (buckets) from 0 to 1000 in steps of 100 (0-99, 100-199, ..., 900-999, 1000+). For each bucket, count the number of orders and calculate the total revenue. Return bucket_start, bucket_end, order_count, and total_revenue.

Schema

🔑idINT
🔗customer_idINT
order_dateTEXT
statusTEXT
total_amountREAL
postgresql

Run your query to see results

Press Ctrl + Enter to execute