mysql实现复杂groupby : GROUP_CONCAT

 

 

 

select che,GROUP_CONCAT(concat_ws(':',routeNo,num)  ORDER BY num DESC SEPARATOR ',') as gg
from 
    (select  che,routeNo,count(distinct paicheNo) as num
    from tableA
    where carrierType=1 and length(deptName)>1 and paicheCreateTime >= date_sub(now(),interval 4 WEEK) and length(che)>5 and  che not like '%汇%'
    group by che,routeNo order by che,num desc) a
group by che
limit 5;

 

转载于:https://www.cnblogs.com/andylhc/p/9805742.html

你可能感兴趣的:(mysql实现复杂groupby : GROUP_CONCAT)