首页 > 编程语言 > 详细

分组排序 SUBSTRING_INDEX--------GROUP_CONCAT

时间:2019-03-13 11:52:26      阅读:254      评论:0      收藏:0      [点我收藏+]

分组查询一定时间段的一组数据 并且需要获取最近的一条数据
使用
SUBSTRING_INDEX
GROUP_CONCAT  默认 , 链接  可以用SEPARATOR 进行字符定义
GROUP_CONCAT(created_at ORDER BY created_at DESC
SEPARATOR ‘-‘
)  对应的截取字符串时 也要相应修改
GROUP是组,CONCAT合并多个字符串,它的功能是:将group by产生的同一个分组中的值连接起来,返回一个字符串结果  
SUBSTRING_INDEX  截取字符串有效位数
select count(uid) as num, id,eid,created_at,uid,
GROUP_CONCAT(created_at ORDER BY created_at DESC) AS created_at from ds_ask_person
where eid=:eid and created_at >= :start and created_at <= :end group by uid order by created_at desc limit :offset,:limit

技术分享图片


select count(uid) as num, id,eid,created_at,uid,
SUBSTRING_INDEX(GROUP_CONCAT(created_at ORDER BY created_at DESC),‘,‘,1) AS created_at from ds_ask_person
where eid=:eid and created_at >= :start and created_at <= :end group by uid order by created_at desc limit :offset,:limit

技术分享图片

 

可参考 https://blog.csdn.net/lvoelife/article/details/81781802

分组排序 SUBSTRING_INDEX--------GROUP_CONCAT

原文:https://www.cnblogs.com/JdsyJ/p/10521810.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!