Cities With Completed Trades

You are given the tables below containing information on Robinhood trades and users. Write a query to list the top three cities that have the most completed trade orders in descending order.

Output the city and number of orders.

table name:


Solution:

select top 3 u.city,count(order_id) as total_orders from trades as t
join users as u on t.user_id = u.user_id
where t.status = 'Completed'
group by u.city
order by total_orders desc

Output:


SQL Script:


Comments (0)