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.
| id INTEGER | name TEXT | department TEXT | job_title TEXT | salary INTEGER | hire_date TEXT | manager_id INTEGER |
|---|---|---|---|---|---|---|
| 1 | Faisal Adnan | Management | Director | 520000 | 2018-03-01 | NULL |
| 2 | Rabia Siddiqui | Finance | Finance Manager | 310000 | 2019-06-15 | 1 |
| 3 | Kamran Yousaf | Finance | Accountant | 150000 | 2021-01-10 | 2 |
| 4 | Saima Noor | Finance | Accountant | 165000 | 2020-09-01 | 2 |
| 5 | Adeel Mirza | Finance | Analyst | 130000 | 2023-02-20 | 2 |
| 6 | Nadia Rehman | Engineering | Engineering Lead | 450000 | 2019-01-07 | 1 |
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).
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
