Skip to content
RED SAGSkills

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_idregionsale_dateamount
1Dubai2025-01-151000
2Dubai2025-04-021500
3Dubai2025-11-30700
4Abu Dhabi2025-03-31400
5Abu Dhabi2025-07-01900
6Sharjah2025-06-30300
7Sharjah2025-06-01200
8Dubai2024-12-315000
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

SQL (SQLite)

Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.