Interview › Second highest

SQL interview: second-highest salary / order

Second highest is a ranking problem. Nested MAX works until there is a tie and someone asks for the row.

Prompt. Return the customer with the second-highest lifetime spend, and the spend.

Hint: ROW_NUMBER on the aggregated spend

DENSE_RANK = 2 returns every customer tied for second. Say so in the interview.

Then write it on a ticket

Monday is free. A colleague asks, you type, we mark it.

Clock in free