select product_id,
count(*) cnt
from (
select substring(order_id from 6 for 9) product_id
from order_log
) as t
group by product_id
order by cnt desc
limit 1
对于取最多的那个:
只能用先分组,再计数,然后倒序排序,最后限制输出第一个
不能直接max(count(*)),因为一旦分组了,那么所有的聚合函数都是对分组后的每组内部进行计算,最后会得出一列值(很多组,每组一个值,只有一个值的max毫无意义,并不能起到对所有组的值取最大的作用)

京公网安备 11010502036488号