users(user_id, city) and trades(trade_id, user_id, status, amount)
Return the top three cities by number of completed trades, as city and
completed_trade_count. Most trades first; break ties by city alphabetically.
status holds other values besides 'completed', and they must not be counted.
Tables
trades
trade_id user_id status amount
-------- ------- --------- ------
1 1 completed 10.00
2 1 completed 20.00
3 2 completed 30.00
4 3 completed 40.00
5 3 completed 50.00
6 4 completed 60.00
7 4 completed 70.00
8 5 completed 80.00
... 3 more row(s)
users
user_id city
------- ------
1 Lagos
2 Lagos
3 Oslo
4 Cairo
5 Boston
Expected result
city completed_trade_count
----- ---------------------
Lagos 3
Cairo 2
Oslo 2
Sign in to write and run your own code.
SELECT query