Skip to content

Instantly share code, notes, and snippets.

View jason-mcdermott's full-sized avatar

Jason McDermott jason-mcdermott

  • Rightpoint Consulting
View GitHub Profile
/*
Given a table of employees and salaries
find the second-highest paid employee
*/
DECLARE @Temp TABLE (EmployeeId INT, Salary INT)
INSERT INTO @Temp VALUES (1, 100000)
INSERT INTO @Temp VALUES (2, 110000)
INSERT INTO @Temp VALUES (3, 120000)
INSERT INTO @Temp VALUES (4, 130000)
/*
sql transform this result
A, 1, q
A, 2, r
A, 3, x
B, 1, q
B, 2, q
to this