mysql 统计最近七天的 数据
当前时间的前七天数据
select DATE_FORMAT(mycreatedate,'%Y-%m-%d') as name,ifnull(COUNT(pv.event_time), 0) as count 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 (select e.event_time from sys_event e LEFT JOIN sys_applets a on e.openid=a.openid where a.position_type=#{type}) pv
on DATE_FORMAT(pv.event_time,'%Y-%m-%d')=total.mycreatedate GROUP BY mycreatedate ORDER BY mycreatedate asc