1541. Top Travellers
My accepted SQL solution to LeetCode problem 1541, Top Travellers, running in 934ms.
- Difficulty: Easy
- SQL
- Runtime 934ms
- Memory 0.0B
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
SQL
Accepted on LeetCode — runtime 934ms, memory 0.0B, accepted 2025-12-29.
SELECT u.name, COALESCE(SUM(r.distance), 0) AS travelled_distance
FROM Users u
LEFT JOIN Rides r ON u.id = r.user_id
GROUP BY u.id, u.name
ORDER BY travelled_distance DESC, u.name ASC