mysql find_in_set()

本文介绍了一个复杂的SQL查询案例,该查询涉及多个表的联接、分组和排序操作,并使用了group_concat函数来聚合特定的数据集。此外,还讨论了解决SQL大小写敏感性和group_concat数据量限制的问题。

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

select
  new.UniqueId,
  task.Id,
  task.Status,
  task.saasEnv,
  task.AppId,
  task.CreateTime,
  task.LastUpdateTime
from
  (select
     uniqueId,
     count(id)                                       as count,
     group_concat(id order by id desc separator ',') as taskIdGroup
   from xx.task
   where id in (select taskId
                from xx.task_bury_point_log
                where code = '100803' and createTime > '2018-05-18 00:00:00')
   group by BINARY UniqueId) as new, xx.task as task
where
  CreateTime >= '2018-05-18 00:00:00' and BINARY task.UniqueId = new.UniqueId and find_in_set(task.id, new.taskIdGroup)
order by task.id desc;

纠结在没办法select id in group_concat(id order by id desc separator ',') ,搜索了下,总算找到个好用的办法。。
糟心

后来又发现,没设置区分大小写。只好再加上BINARY关键字。。

实际使用中发现,group_concat有数据量大小限制。。继续修改...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值