SQL
All Top 50 SQL Interview Questions#33
Find Employees Earning Above Department Average in SQL
MediumPwCInterview Question #33
Asked at PwCGiven `employees` (emp_id, emp_name, department_id, salary), find all employees whose salary is strictly greater than the average salary of their respective department.
Input Table: employees
4 rows preview| emp_id | emp_name | department_id | salary |
|---|---|---|---|
| 1 | Sachin | 10 | 85000 |
| 2 | Rahul | 10 | 65000 |
| 3 | Shreya | 20 | 95000 |
| 4 | Ananya | 20 | 92000 |
Expected Output Structure2 rows
| emp_id | emp_name | department_id | salary |
|---|---|---|---|
| 1 | Sachin | 10 | 85000 |
| 3 | Shreya | 20 | 95000 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.