-- 1위 한 명만
SELECT o.customer_number
FROM orders o
GROUP BY o.customer_number
ORDER BY COUNT(*) DESC
LIMIT 1
;
-- 1위 여러 명
SELECT customer_number
FROM orders
GROUP BY customer_number
HAVING COUNT(customer_number) >= ALL
(SELECT COUNT(customer_number) FROM orders GROUP BY customer_number)
;
스키마
Create table If Not Exists orders (order_number int, customer_number int);
Truncate table orders;
insert into orders (order_number, customer_number) values (1, 1);
insert into orders (order_number, customer_number) values (2, 2);
insert into orders (order_number, customer_number) values (3, 3);
insert into orders (order_number, customer_number) values (4, 3);