数据库
首页 > 数据库> > 查询7天sql

查询7天sql

作者:互联网

SELECT 
t.stime ,CASE WHEN ISNULL(u.forum_count) THEN '0' ELSE u.forum_count END  AS count 	
FROM (
	SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY) AS stime 
	UNION  SELECT DATE_SUB(CURDATE(), INTERVAL 2 DAY) AS stime
	UNION  SELECT DATE_SUB(CURDATE(), INTERVAL 3 DAY) AS stime
	UNION  SELECT DATE_SUB(CURDATE(), INTERVAL 4 DAY) AS stime
	UNION  SELECT DATE_SUB(CURDATE(), INTERVAL 5 DAY) AS stime
	UNION  SELECT DATE_SUB(CURDATE(), INTERVAL 6 DAY) AS stime
	UNION  SELECT DATE_SUB(CURDATE(), INTERVAL 7 DAY)AS stime
	)  t 
	LEFT JOIN cms_user_active_statistics u 
	ON CAST(u.statistics_time AS DATE) <= t.stime
	GROUP BY t.stime
	ORDER BY t.stime asc

标签:SUB,INTERVAL,查询,stime,sql,DATE,DAY,SELECT
来源: https://blog.csdn.net/qq_38006148/article/details/120142259