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;

 

posted on 2018-10-17 17:47  andy_1  阅读(1478)  评论(0编辑  收藏  举报

导航