THẬN TRỌNG:truy vấn sẽ không xử lý các bản ghi trùng lặp có COUNT
tối đa
SELECT commodity, COUNT(commodity) `count`
FROM orders
GROUP BY commodity
ORDER BY `count` DESC
LIMIT 1
Nhưng điều này sẽ,
SELECT commodity, COUNT(commodity) `count`
FROM orders
GROUP BY commodity
HAVING COUNT(commodity) =
(
SELECT MAX(`COUNT`)
FROM
(
SELECT COUNT(commodity) `count`
FROM orders
GROUP BY commodity
) s
)