码迷,mamicode.com
首页 > 其他好文 > 详细

统计最近几天的分组数据

时间:2017-11-08 15:58:14      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:ase   font   pre   功能   合并   number   inter   blog   com   

实现功能,对用户的访问做统计,最近7天的访问人数(1-7连续的),可以按照浏览器,或者其他条件进行分组,合并之后按时间排序
select group_concat(countValue order by sst.countKey),group_concat(countKey order by sst.countKey),brower from ( select DATE_FORMAT(mycreatedate,‘%m-%d‘) as countKey,ifnull(COUNT(pv.create_date), 0) as countValue ,pv.brower from ( SELECT curdate() as mycreatedate union all SELECT date_sub(curdate(), interval 1 day) as mycreatedate union all SELECT date_sub(curdate(), interval 2 day) as mycreatedate union all SELECT date_sub(curdate(), interval 3 day) as mycreatedate union all SELECT date_sub(curdate(), interval 4 day) as mycreatedate union all SELECT date_sub(curdate(), interval 5 day) as mycreatedate union all SELECT date_sub(curdate(), interval 6 day) as mycreatedate ) as total LEFT JOIN base_log_event pv on DATE_FORMAT(pv.create_date,‘%Y-%m-%d‘)=total.mycreatedate GROUP BY mycreatedate,pv.brower ) sst group by sst.brower

技术分享

注意,如果要对分组合并数据排序group_concat(ss order by ddd)这样写

统计最近几天的分组数据

标签:ase   font   pre   功能   合并   number   inter   blog   com   

原文地址:http://www.cnblogs.com/longsanshi/p/7804297.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!