Quarterly Sales Pivot
Turn sales into one row per region with one column per quarter of the year 2025. Q1 is January to March, Q2 April to June, Q3 July to September, Q4 October to December. A quarter with no sales shows 0. Sales from other years are ignored, and a region with no 2025 sales does not appear. Round each total with ROUND(x, 2).
Return columns region, q1, q2, q3, q4. Order by region ascending.
Schema
CREATE TABLE sales ( sale_id INTEGER PRIMARY KEY, region TEXT NOT NULL, sale_date TEXT NOT NULL, amount REAL NOT NULL );
Sample data
sales
| sale_id | region | sale_date | amount |
|---|---|---|---|
| 1 | Dubai | 2025-01-15 | 1000 |
| 2 | Dubai | 2025-04-02 | 1500 |
| 3 | Dubai | 2025-11-30 | 700 |
| 4 | Abu Dhabi | 2025-03-31 | 400 |
| 5 | Abu Dhabi | 2025-07-01 | 900 |
| 6 | Sharjah | 2025-06-30 | 300 |
| 7 | Sharjah | 2025-06-01 | 200 |
| 8 | Dubai | 2024-12-31 | 5000 |
Hint 1
Conditional aggregation: SUM(CASE WHEN <in quarter> THEN amount ELSE 0 END), once per quarter.
Hint 2
strftime('%m', d) returns the month as text such as '04'; cast it to an integer before comparing ranges.
Good practice for: Data Analyst, Business Analyst, Data Engineer
Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.