▸_sqlgym

28. Departments Above Average Headcount

MediumAdvanced Filteringaggregate of aggregatessubquery in WHERE

To compare a group's size against the average group size, you aggregate once to get per-group counts, then aggregate again over those counts.

Task: return the departments whose headcount is strictly greater than the average headcount across all departments. Columns: dept, cnt. Order by cnt descending, then dept.

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
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.