Customer Placing the Largest Number of Orders
EasyLeetCodeSQL: Aggregation & GROUP BY
Hint and exampleShowHide
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
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | Classes With at Least 5 Students | LeetCode | Easy | Solve Classes With at Least 5 Students on LeetCode (opens in a new tab) | |||
| 2 | Duplicate Emails | LeetCode | Easy | Solve Duplicate Emails on LeetCode (opens in a new tab) | |||
| 3 | Number of Unique Subjects Taught by Each Teacher | LeetCode | Easy | Solve Number of Unique Subjects Taught by Each Teacher on LeetCode (opens in a new tab) | |||
| 4 | Customer Placing the Largest Number of Orders | LeetCode | Easy | Solve Customer Placing the Largest Number of Orders on LeetCode (opens in a new tab) | |||
| 5 | Biggest Single Number | LeetCode | Easy | Solve Biggest Single Number on LeetCode (opens in a new tab) |