SQL QuestSQL Interview Questions › Aggregation & Grouping

Department Compensation Report

MediumFreeQuerying BasicsAggregation & GroupingConditional Logic

For departments with 3 or more employees, show: department, headcount, total_salary_budget (SUM), avg_salary (rounded to nearest dollar), max_salary, and high_performer_pct (% with performance_rating >= 4.0, 1 decimal). Sort by total_salary_budget descending.

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: Departments with 3+ employees and full compensation stats

Hint

HAVING COUNT(*) >= 3 filters small departments. high_performer_pct = ROUND(100.0 * SUM(CASE WHEN performance_rating >= 4.0 THEN 1 ELSE 0 END) / COUNT(*), 1)

Concepts

SELECT GROUP BY HAVING Aggregation CASE

Practise the topic: SQL practice questions · GROUP BY exercises · CASE WHEN practice

In these company practice sets

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 · FreeConsistent Director AnalysisMedium · 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