susinlee 님의 블로그
Cities With Completed Trades 본문
[문제]
https://datalemur.com/questions/completed-trades
Robinhood SQL Interview Question | DataLemur
Robinhood SQL Interview Question: Write a query to find the cities with the highest completed trades.
datalemur.com
[풀이]
1. 두 테이블을 병합한 후 완료된 주문만 필터링
2. 도시별로 그룹화 한뒤 주문 개수를 계산하고 개수를 기준으로 내림차순 정렬
3. 상위 3개만 반환
[코드]
SELECT city, COUNT(order_id) AS total_orders
FROM trades t
JOIN users u
ON t.user_id = u.user_id
WHERE status = 'Completed'
GROUP BY city
ORDER BY total_orders DESC
LIMIT 3
'코드카타 > SQL, Pandas' 카테고리의 다른 글
Supercloud Customer (0) | 2025.03.09 |
---|---|
Signup Activation Rate (0) | 2025.03.09 |
Duplicate Job Listings (0) | 2025.03.09 |
Active User Retention (0) | 2025.03.08 |
Top 5 Artists (0) | 2025.03.08 |