SQL QuestSQL Interview Questions › Aggregation & Grouping

Highest Total Salary Budget Department

MediumFreeQuerying BasicsAggregation & GroupingSubqueries & CTEs

Finance asks Google's People Analytics team every fiscal planning cycle: which department has the highest total salary budget? (Sum of all salaries, not average — headcount matters.) Return department, total_budget, headcount, and avg_salary (rounded to nearest dollar). Use a subquery in HAVING to match the maximum total. Order by department ascending (safety tie-breaker in case two departments tie for the top budget). This nested-aggregation pattern — MAX of SUMs — is a Google-favorite interview because you have to think one level deeper than 'just GROUP BY'.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

employees

emp_idnamedepartmentpositionsalaryhire_datemanager_idperformance_rating
1Alice JohnsonEngineeringSenior Developer950002019-03-1554.5
2Bob SmithEngineeringDeveloper750002020-06-0113.8
3Carol WilliamsMarketingMarketing Manager850002018-09-20NULL4.2

Expected output: Single department with the largest combined salary spend

Hint

GROUP BY department, then HAVING SUM(salary) = (SELECT MAX(dept_total) FROM (SELECT SUM(salary) AS dept_total FROM employees GROUP BY department))

Concepts

SELECT GROUP BY Aggregation Subquery HAVING

Practise the topic: SQL practice questions · GROUP BY exercises · CTE practice

In these company practice sets

Google · Snowflake

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Class Survival BreakdownMedium · FreeDepartment Roster with GROUP_CONCATMedium · FreeMovie Rating Tier BreakdownMedium · FreeFull Survival Dashboard by ClassMedium · FreeGenre Financial ReportMedium · FreeDepartment Compensation ReportMedium · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test