mysql 查询指定月份的每一天日期

mysql 查询指定月份的每一天日期 日期:2023-02 ,传入SQL 2023-02-01

	SELECT
	date_add(
	DATE_ADD( DATE_FORMAT( '2023-02-01', '%Y-%m-%d' ), INTERVAL - DAY ( DATE_FORMAT( '2023-02-01', '%Y-%m-%d' ) ) + 2 DAY ),
	INTERVAL ( cast( help_topic_id AS signed INTEGER ) - 1 ) DAY 
	) DAY 
FROM
	mysql.help_topic 
WHERE
	help_topic_id < DAY ( last_day( DATE_FORMAT( '2011-02-01', '%Y-%m-%d' ) ) ) 
ORDER BY
	help_topic_id

查询当月的每一天,由1号开始,到当月结束日期


SELECT
date_add(DATE_ADD(curdate(), INTERVAL - DAY(curdate()) + 2 DAY), INTERVAL (cast( help_topic_id AS signed INTEGER ) - 1 ) DAY ) DAY 
from mysql.help_topic
where help_topic_id  < day(last_day(curdate()))
order by help_topic_id

查询当天起未来一个月(30天)的每一天 

select 
date_add(curdate(), interval(cast(help_topic_id as signed integer) ) day) day
from mysql.help_topic
where help_topic_id  < day(last_day(curdate()))
order by help_topic_id

查询当前时间24小时每一小时时间

SET @i=-1;
SELECT DATE_SUB( NOW(),INTERVAL ( (@i:=@i+1) ) HOUR ) AS 'time'
FROM  mysql.help_category 
WHERE @i<23

你可能感兴趣的:(mysql,数据库)