Cities With Completed Trades
Robinhood 👶 Easy SQL
Beginner Mode

Objective

Write a SQL query to identify the top three cities by number of completed trade orders.

Table Schema:

  • trades
Column Type Description
order_id INTEGER Unique identifier for each trade order
user_id INTEGER ID of the user who placed the order
status VARCHAR Status of the trade order (e.g., 'Completed', 'Cancelled', 'Pending')
  • users
Column Type Description
user_id INTEGER Unique identifier for each user
city VARCHAR City where the user is located

Task Requirements:

  • Filter only trades with status 'Completed'
  • Join trades with user details to get city information
  • Count the number of completed orders per city
  • Return the top three cities with the highest order counts
  • Sort results in descending order by order count

Output columns: city, total_orders

Examples

Example 1:

Input:

trades
order_idstatususer_id
1Completed101
2Completed102
3Completed103
4Completed104
5Cancelled105
users
cityuser_id
New York101
New York102
San Francisco103
Boston104
Chicago105

Output:
citytotal_orders
New York2
Boston1
San Francisco1
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →