Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

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.

TSQL Beginners Challenge 1 - Find the second highest salary for each department

Solution to TSQL Beginners Challenge 1 - Find the second highest salary for each department

Apr 12 2012 12:00AM by lyqandgdp   

Use CTE, and ROW_NUMBER

;WITH T AS
(
SELECT *, 
ROW_NUMBER() OVER (PARTITION BY Department ORDER BY Salary DESC) AS Ord
FROM @Employees
)
SELECT * 
FROM T t1 
WHERE EXISTS 
(
	SELECT *
	FROM T t2 
	WHERE t1.Department = t2.Department
	AND t2.Ord = 2
	AND t1.Salary=t2.Salary
)

Tags:


lyqandgdp
350 · 0% · 116
1



Submit

Your Comment


Sign Up or Login to post a comment.

"Solution to TSQL Beginners Challenge 1 - Find the second highest salary for each department " rated 5 out of 5 by 1 readers
Solution to TSQL Beginners Challenge 1 - Find the second highest salary for each department , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]