All problems

The Analyst's First Query

easySQLAggregation

It is your first day as a People Analytics intern at Kestrel Labs, and nobody trusts the new warehouse yet. The employee records were copied over from the old HR system last night, and a copy that quietly drops rows looks exactly like a copy that worked. Before anyone builds a dashboard on top of this data, your manager wants the one number she can hold up against the HR system's own figure: how many employee records the warehouse actually contains.

employees — one row per person. department_id is the team they sit on, given as the matching id in departments; salary is annual pay in dollars; hire_date is the day they started, written year-month-day; manager_id is the id of the person they report to, and is NULL for anyone who reports to nobody.

id name department_id salary hire_date manager_id
1 Ava Chen 1 145000 2021-03-14 NULL
2 Ben Ortiz 1 118000 2022-06-01 1
3 Cara Novak 1 121000 2023-01-10 1
4 Deshawn Lee 2 95000 2020-09-23 NULL
5 Elin Kask 2 88000 2022-11-05 4
6 Farid Amiri 3 76000 2023-04-18 NULL
7 Grace Kim 4 132000 2021-07-30 NULL
8 Hugo Silva 4 110000 2023-02-14 7
9 Ines Duarte 4 104000 2023-08-01 7
10 Jonas Weber 2 91000 2021-12-19 4

The table already exists in the database — there is nothing to create or load.

Task: Write a query returning one row with a single column, total_employees, holding how many rows the employees table contains. Every record counts, including the people whose manager_id is NULL — a missing manager does not make someone less of an employee.

Example output — the shape, on an invented figure. A company of forty-seven people would come back as:

total_employees
47

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…