Hard
CTE

Top Earner Per Department (CTE)

Using a CTE, find the highest-paid employee in each department. Return columns: department_id, first_name, last_name, max_salary. Order results by: e.department_id.

Preparing the interactive SQL workspace...

Challenge overview

What you will practice

Using a CTE, find the highest-paid employee in each department. Return columns: department_id, first_name, last_name, max_salary. Order results by: e.department_id.

Difficulty
Advanced
SQL concept
CTE

Public schema and sample data

departments

id INTEGERname TEXTbudget REALlocation TEXT
1Engineering1500000New York
2Marketing800000London
3Sales600000Chicago

employees

id INTEGERfirst_name TEXTlast_name TEXTemail TEXTdepartment_id INTEGERsalary REALhire_date TEXTmanager_id INTEGER
1AliceJohnsonalice@corp.com1950002019-03-15NULL
2BobSmithbob@corp.com1850002020-06-011
3CarolWilliamscarol@corp.com2720002018-11-20NULL