ExpertSubqueries50 points

Employees paid above their department average

HR is reviewing pay fairness. They want to see the employees who earn more than the average salary of their own department.

Task: return the employee name, department and salary of everyone above their department's average, ordered by department and then by salary from highest to lowest.

The data you can query

Each table is shown with its column types and the first rows, so you can see exactly what the data looks like.

employees20 rows
id INTEGERname TEXTdepartment TEXTjob_title TEXTsalary INTEGERhire_date TEXTmanager_id INTEGER
1Faisal AdnanManagementDirector5200002018-03-01NULL
2Rabia SiddiquiFinanceFinance Manager3100002019-06-151
3Kamran YousafFinanceAccountant1500002021-01-102
4Saima NoorFinanceAccountant1650002020-09-012
5Adeel MirzaFinanceAnalyst1300002023-02-202
6Nadia RehmanEngineeringEngineering Lead4500002019-01-071

Showing the first 6 of 20 rows.

Your query runs on SQLite. Write a single SELECT; use LIMIT instead of TOP.

Need a hint?

Compare each salary with the average of the same department, using a correlated subquery or a window function AVG(salary) OVER (PARTITION BY department).