mysql实现复杂groupby : GROUP_CONCAT

本文深入解析了一段复杂的SQL查询语句,该语句用于从tableA中选择特定条件下的che和routeNo,并按num字段降序进行GROUP_CONCAT操作。查询涉及了多个筛选条件,包括carrierType、deptName长度、paicheCreateTime的时间范围、che长度以及che不包含'汇'字等。通过此查询,可以有效地获取到符合要求的数据集合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值