FunctionRacerProblemsRace

Top Two Salaries per Department

HardSQLSQLite

In each department, take its two highest salaries, counting equal salaries once. Return the dept, name and salary of everyone who is paid one of those two. A department with only one salary level returns everyone on it. Rows may come in any order.

Example 1

employees
idnamedeptsalary
1Adaops5000
2Benops5000
3Cyops4000
4Deeops3000
5Elirisk6000
returns
deptnamesalary
opsAda5000
opsBen5000
opsCy4000
riskEli6000

Constraints

Race itor take your time

Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.

More SQL problems