Cumulative Hires by Year
Using each employee's hire_date, count hires per calendar year and keep a running total of all hires up to and including that year. Only years with at least one hire appear. hire_year must be an integer.
Return columns hire_year, hires, cumulative_hires. Order by hire_year ascending.
Schema
CREATE TABLE employees ( emp_id INTEGER PRIMARY KEY, name TEXT NOT NULL, hire_date TEXT NOT NULL );
Sample data
employees
| emp_id | name | hire_date |
|---|---|---|
| 1 | Abe | 2021-03-15 |
| 2 | Bo | 2021-11-01 |
| 3 | Cy | 2022-02-10 |
| 4 | Di | 2023-06-30 |
| 5 | Ed | 2023-07-01 |
| 6 | Flo | 2023-12-31 |
| 7 | Gil | 2025-01-02 |
Hint 1
Aggregate to one row per year, then apply SUM(...) OVER (ORDER BY year).
Good practice for: Data Analyst, Business Analyst, Data Scientist
SQL (SQLite)
Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.