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

Mar 6 2010 4:13AM by CAReitan   

Solution to TSQL Beginners Challenge 1

DECLARE @Employees TABLE( 
   
EmployeeID INT IDENTITY, 
   
EmployeeName VARCHAR(15), 
   
Department VARCHAR(15), 
   
Salary NUMERIC(16,2) 
) 

 INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('T Cook','Finance', 40000) 
INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('D Michael','Finance', 25000) 
INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('A Smith','Finance', 25000) 
INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('D Adams','Finance', 15000)  
 
 INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('M Williams','IT', 80000) 
INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('D Jones','IT', 40000) 
INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('J Miller','IT', 50000) 
INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('L Lewis','IT', 50000) 
 
 
INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('A Anderson','Back-Office', 25000) 
INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('S Martin','Back-Office', 15000) 
INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('J Garcia','Back-Office', 15000) 
INSERT INTO @Employees(EmployeeName, Department, Salary) 
VALUES('T Clerk','Back-Office', 10000)

SELECT X.EmployeeID
		,X.EmployeeName
		,X.Department
		,X.Salary
FROM
(SELECT EmployeeID
		,EmployeeName
		,Department
		,Salary
		,RANK() OVER(Partition BY Department ORDER BY Salary) AS [Sal Rank]
FROM @Employees) AS X
WHERE X.[Sal Rank]=2;

Tags:


CAReitan
908 · 0% · 30
0
Liked



Submit

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]