Code RoomSalary gap to department top
HardPrep Room Coding #5065

Salary gap to department top

SQLAlgorithms & data structuresSenior~12 min

For each employee with a recorded salary, return `name`, `salary`, and `gap_to_top`: how far their salary sits below the highest in their own department. Order by name.

What a strong answer looks like

Say what the query is meant to return before you write it, and name the shape of the answer: how many rows, grouped by what. Then watch the NULLs and the duplicates, because that is where most of these are lost.

Run onlyA query runs as one statement, so there is nothing to step through. Run it and read the rows.

0:00 of about 12 min

Expected, in this order

namesalarygap_to_top
Ada1800000
Grace16500015000
Jean1500000
Kay1200000
Linus14000040000
Mel1200000

Your result

Run your query to compare.

1 more set of rows are waiting. Free with an account.