32. Headcount per Department
EasyJoinsINNER JOINGROUP BYCOUNT
The bread-and-butter reporting pattern: join two tables, then aggregate. Join employees to their department, group by department, and count.
Task: return each department's name and how many employees work in it. Only departments that actually have employees should appear (use an inner join).
Output columns, in this exact order: department, headcount. Order by headcount descending, breaking ties by department ascending.
Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…
This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases — 5test cases in all. A sloppy query that only fits the example won't pass.
SQL· SQLite · runs in your browser
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.