1. 程式人生 > >統計最近幾天的分組數據

統計最近幾天的分組數據

() con %d eve nio word 合並 logs 技術

實現功能,對用戶的訪問做統計,最近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)這樣寫

統計最近幾天的分組數據