Skip to content

Instantly share code, notes, and snippets.


Jason McDermott jason-mcdermott

  • Rightpoint Consulting
View GitHub Profile
View SQL Top 2 problem.sql
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)
View Sql group and transform.sql
sql transform this result
A, 1, q
A, 2, r
A, 3, x
B, 1, q
B, 2, q
to this