▸_sqlgym

4. Second Highest Salary (DENSE_RANK)

MediumRankingDENSE_RANKfilter on rank

DENSE_RANK assigns 1 to the highest value, 2 to the next distinct value, and so on — no gaps. That makes "the Nth highest distinct value" a one-liner.

Task: return the employees who earn the second highest distinct salary. Several people can tie for it. Return name and salary, ordered by name.

Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…

This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases 5test cases in all. A sloppy query that only fits the example won't pass.

SQL
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.