The challenge is to find the employees with the second highest salary in each department. However, it is a little more complicated because if two employees have the same salary, you need to list both of them.
Solution to TSQL Beginners Challenge 1
select EmployeeID,EmployeeName,Department,Salary from ( Select *,Dense_Rank() over (Partition by Department order by Salary desc) as RANK from Employees ) V where RANK = 2
Tags: