Quarter by quarter: how fast is Nordvik growing?
The board wants a growth chart for 2024 Q3 to 2026 Q2 (eight quarters). No calendar table exists, so you must generate the quarters yourself with a recursive CTE. For each quarter we need people who joined, people who left and the headcount on the last day of the quarter: employees hired on or before that day who had not left by then (a leaver whose termination_date is after the quarter end still counts as employed at quarter end).
Task: return quarter (text like 2025-Q1), hires (hire_date inside the quarter), leavers (termination_date inside the quarter), headcount (as defined above) and growth_pct (percentage change of headcount versus the previous quarter, ROUND(x, 2), NULL for the first quarter). Sort by quarter ascending.
The data you can query
Each table is shown with its column types and the first rows, so you can see exactly what the data looks like.
| dept_id INTEGER | name TEXT |
|---|---|
| 1 | Engineering |
| 2 | Sales |
| 3 | Finance |
| 4 | People & Culture |
| 5 | Marketing |
| 6 | Operations |
Showing the first 6 of 7 rows.
| emp_id INTEGER | name TEXT | dept_id INTEGER | job_title TEXT | country TEXT | grade INTEGER | salary_usd INTEGER | hire_date TEXT | termination_date TEXT | manager_id INTEGER |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Harry Clarke | 7 | Chief Executive Officer | United Kingdom | 9 | 375000 | 2016-03-01 | NULL | NULL |
| 2 | Khalid Al Hashimi | 1 | VP of Engineering | United Arab Emirates | 8 | 237000 | 2021-03-01 | NULL | 1 |
| 3 | Zainab Ahmed | 1 | Director of Engineering 1 | Pakistan | 7 | 59000 | 2021-10-12 | NULL | 2 |
| 4 | Hina Khan | 1 | Engineering Manager | Pakistan | 6 | 40000 | 2024-08-10 | NULL | 3 |
| 5 | Ren Tanaka | 1 | QA Engineer | Japan | 4 | 68000 | 2022-12-19 | NULL | 4 |
| 6 | Piotr Zielinski | 1 | Data Engineer | Poland | 3 | 33000 | 2025-10-23 | NULL | 4 |
Showing the first 6 of 58 rows.
| review_id INTEGER | emp_id INTEGER | review_period TEXT | rating INTEGER | reviewed_on TEXT |
|---|---|---|---|---|
| 1 | 2 | 2024-H2 | 2 | 2024-12-20 |
| 2 | 2 | 2025-H1 | 1 | 2025-06-18 |
| 3 | 2 | 2025-H2 | 3 | 2025-12-30 |
| 4 | 2 | 2026-H1 | 2 | 2026-06-25 |
| 5 | 3 | 2024-H2 | 3 | 2024-12-29 |
| 6 | 3 | 2025-H1 | 4 | 2025-06-18 |
Showing the first 6 of 178 rows.
| promo_id INTEGER | emp_id INTEGER | promo_date TEXT | old_grade INTEGER | new_grade INTEGER | old_salary_usd INTEGER | new_salary_usd INTEGER |
|---|---|---|---|---|---|---|
| 1 | 3 | 2025-11-26 | 6 | 7 | 50000 | 59000 |
| 2 | 4 | 2025-12-10 | 5 | 6 | 33000 | 40000 |
| 3 | 6 | 2026-05-08 | 2 | 3 | 28000 | 33000 |
| 4 | 7 | 2025-09-14 | 6 | 7 | 120000 | 143000 |
| 5 | 12 | 2025-01-06 | 2 | 3 | 27000 | 29000 |
| 6 | 29 | 2026-02-23 | 6 | 7 | 80000 | 91000 |
Showing the first 6 of 9 rows.
Your query runs on SQLite. Write a single SELECT; use LIMIT instead of TOP.
Need a hint?
Date arithmetic with date(x, '+3 months') walks the quarters. LAG() gives the previous quarter's headcount on the same row.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
