Java教程

查询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
这篇关于查询7天sql的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!