Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
Revenue is reported in USD, but bookings are charged in local currency. FX rates are published on trading days only, so airbnb_fx_rates has no row for a Saturday or Sunday — while bookings happen every day of the week.
Return one row per city, ordered by USD revenue descending.
Result columns · in this order
city | City of the listings. |
bookings | Bookings made there. |
revenue_usd | Their total value converted to USD. |
How to approach it
Run the starter and look for the NULL rates. Those bookings are the question.
Sample input
| booking_id | city | currency | amount_local | booked_on |
|---|---|---|---|---|
| 1 | Lisbon | EUR | 400 | 2026-03-02 |
| 2 | Lisbon | EUR | 250 | 2026-03-07 |
| 3 | Lisbon | EUR | 310 | 2026-03-08 |
| 4 | Tokyo | JPY | 60000 | 2026-03-03 |
| 5 | Tokyo | JPY | 45000 | 2026-03-07 |
| 6 | Tokyo | JPY | 90000 | 2026-03-09 |
| 7 | London | GBP | 320 | 2026-03-02 |
| 8 | London | GBP | 180 | 2026-03-08 |
| 9 | London | GBP | 275 | 2026-03-10 |
| 10 | Austin | USD | 500 | 2026-03-04 |
| 11 | Austin | USD | 220 | 2026-03-08 |
| 12 | Lisbon | EUR | 190 | 2026-03-10 |
12 rows — scroll inside the table to see them all.
| currency | rate_date | rate_to_usd |
|---|---|---|
| EUR | 2026-03-02 | 1.09 |
| EUR | 2026-03-03 | 1.1 |
| EUR | 2026-03-04 | 1.08 |
| EUR | 2026-03-05 | 1.08 |
| EUR | 2026-03-06 | 1.07 |
| EUR | 2026-03-09 | 1.11 |
| EUR | 2026-03-10 | 1.12 |
| JPY | 2026-03-02 | 0.0067 |
| JPY | 2026-03-03 | 0.0066 |
| JPY | 2026-03-04 | 0.0066 |
| JPY | 2026-03-05 | 0.0065 |
| JPY | 2026-03-06 | 0.0065 |
| JPY | 2026-03-09 | 0.0064 |
| JPY | 2026-03-10 | 0.0064 |
| GBP | 2026-03-02 | 1.27 |
| GBP | 2026-03-03 | 1.28 |
| GBP | 2026-03-04 | 1.28 |
| GBP | 2026-03-05 | 1.26 |
| GBP | 2026-03-06 | 1.25 |
| GBP | 2026-03-09 | 1.29 |
| GBP | 2026-03-10 | 1.3 |
| USD | 2026-03-02 | 1 |
| USD | 2026-03-03 | 1 |
| USD | 2026-03-04 | 1 |
| USD | 2026-03-05 | 1 |
| USD | 2026-03-06 | 1 |
| USD | 2026-03-09 | 1 |
| USD | 2026-03-10 | 1 |
28 rows — scroll inside the table to see them all.
Expected output
| city | bookings | revenue_usd |
|---|---|---|
| Tokyo | 3 | 1264.5 |
| Lisbon | 4 | 1248 |
| London | 3 | 988.9 |
| Austin | 2 | 720 |
4 rows — all rows shown.
Constraints
booked_on for that currency.bookings is 4 for Lisbon, 3 for Tokyo, 3 for London and 2 for Austin.revenue_usd is the total converted amount, rounded to 2 decimal places.revenue_usd descending, then city.Worked example
Booking 2 is 250 EUR on 2026-03-07. There is no EUR rate for that date, so the correct rate is the most recent one before it — 1.07, published on 6 March — giving 267.50 USD.
An equi-join on rate_date silently drops that booking, along with the four others made that weekend. Lisbon then reports 2 bookings and 648.80 instead of 4 and 1248.00, and the total understates revenue by roughly a third. Nothing errors; the report is simply smaller than the truth.
What this tests
The as-of lookup against a sparse dimension: when the reference table has gaps, matching on equality drops facts, and the correct join is 'the latest row at or before this date'.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.