🔥 SQL Interview Question of the Day
📌 Scenario:
A company wants to find the highest-paid employee in each department.
You have one table:
employees
• employee_id • employee_name • department • salary
☑ Solution:
SELECT
employee_id,
employee_name,
department,
salary
FROM (
SELECT
*,
DENSE_RANK() OVER (
PARTITION BY department
ORDER BY salary DESC
) AS salary_rank
FROM employees
) e
WHERE salary_rank = 1;
💡 Concept Tested:
Window Functions + DENSE_RANK() (Finding Top Records Within Groups)
❤️ React if you want more SQL interview questions.
Post #2406
1.12K
- ❤ 5