Skip to content
We areTOP 1%

Customer Placing the Largest Number of Orders

EasyLeetCodeSQL: Aggregation & GROUP BY
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Hint and exampleShow

Count the rows in each group, sort the groups by that count in descending order and keep the first group with LIMIT 1.

Example: bookings(id, guest)

id | guest
1  | G1
2  | G2
3  | G2
4  | G3
SELECT guest
FROM bookings
GROUP BY guest
ORDER BY COUNT(*) DESC
LIMIT 1;   -- returns G2 (2 bookings)

More in SQL: Aggregation & GROUP BY

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account