Advertisement
elena1234

Third Highest Salary ( T-SQL )

Jan 5th, 2022 (edited)
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.24 KB | None | 0 0
  1. WITH CTE AS
  2. (
  3. SELECT  DepartmentID, SALARY,
  4. DENSE_RANK() OVER (PARTITION BY DepartmentID ORDER BY SALARY DESC ) RANK_SALARY
  5. FROM Employees
  6. )
  7.  
  8. SELECT DISTINCT (DepartmentID), SALARY AS ThirdHighestSalary
  9. FROM CTE
  10. WHERE RANK_SALARY = 3;
  11.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement