SQL QuestSQL Interview Questions › Aggregation & Grouping

Performance vs Salary Analysis

MediumFreeQuerying BasicsAggregation & GroupingConditional Logic

For each department, compare average salary of high performers (performance_rating >= 4.0) vs others (< 4.0). Show: department, headcount, high_performer_avg_salary, others_avg_salary, and performance_premium (difference, rounded to 0 dec). Sort by performance_premium 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: performance_premium: 20000

Hint

AVG(CASE WHEN performance_rating >= 4.0 THEN salary END) — CASE with no ELSE returns NULL for non-matching rows, which AVG() ignores automatically

Concepts

SELECT GROUP BY CASE Aggregation ORDER BY Conditional Aggregation

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

In these company practice sets

Amazon · Ramp · 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