29/34
Part 6 of 6 · Follow-upsLearn

What interviewers ask next

The practice problem asks how you'd handle days with no bookings. Have that answer ready, and these others with it.

Include the ties: RANK keeps every tie, DENSE_RANK keeps the top levels

Switch ROW_NUMBER to RANK and drop the id from the ORDER BY. Then say what changes: a city can now return three or more listings.

If they mean the listings at the top two revenue levels, that's DENSE_RANK. Walk the difference with a tie for first: both tied listings get rank 1, and only DENSE_RANK gives the next listing a 2.

Show every date, even with no bookings: cross the cities with a calendar

Use the calendar table, crossed with the cities:

  1. Cities CROSS JOIN days.
  2. LEFT JOIN the daily counts.
  3. COALESCE to 0.
  4. PARTITION BY city.

With exactly one row per city per day, ROWS and RANGE give the same frame.