您的当前位置:首页正文

MySQL查询两个日期之间的所有日期

2024-11-30 来源:个人技术集锦

SQL

SELECT
	a.date,
	COUNT( um.id ) quantity 
FROM
	(
	SELECT
		@num := @num + 1 num,
		date_format( adddate( '2021-12-01', INTERVAL @num DAY ), '%Y-%m-%d' ) AS date 
	FROM
		visit_record,(
		SELECT
			@num :=- 1 
		) t 
	) a
	LEFT JOIN user_member um ON DATE_FORMAT( um.auth_time, '%Y-%m-%d' )= a.date 
	AND um.auth = 1 
WHERE
	a.date BETWEEN '2021-12-01' 
	AND '2021-12-31' 
GROUP BY
	a.date

注意有个前提:必须要有一个表,它的数据条数大到足够支撑你要查询的天数

涉及到的函数

显示全文