SQL
All Top 50 SQL Interview Questions#21
Aggregate Monthly Revenue and Order Volumes in SQL
EasyFlipkartInterview Question #21
Asked at FlipkartGiven an `orders` table, write a SQL query to calculate the total revenue and total number of successful orders for each month. Sort chronologically.
Input Table: orders
4 rows preview| order_id | order_date | amount | status |
|---|---|---|---|
| 1 | 2026-01-10 | 1200 | success |
| 2 | 2026-01-25 | 800 | success |
| 3 | 2026-02-05 | 2500 | success |
| 4 | 2026-02-15 | 300 | cancelled |
Expected Output Structure2 rows
| order_month | order_count | total_revenue |
|---|---|---|
| 2026-01 | 2 | 2000 |
| 2026-02 | 1 | 2500 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.