1、获取指定时间区间内的所有日期
SELECT
date_add( '2022-04-01', INTERVAL ( cast( help_topic_id AS signed INTEGER )) DAY ) day
FROM
mysql.help_topic
WHERE
help_topic_id < datediff( '2022-05-01', '2022-04-01' ) + 1
ORDER BY
help_topic_id
2、获取当天内所有时段
SELECT DATE_FORMAT( DATE_SUB( DATE_FORMAT( NOW(), '%Y-%m-%d' ), INTERVAL (-( @i := @i + 1 )) HOUR
),
'%Y-%m-%d %H'
) AS 'time'
FROM
(
SELECT
a
FROM
( SELECT '1' AS a UNION SELECT '2' UNION SELECT '3' UNION SELECT '4' ) AS a
JOIN ( SELECT '1' UNION SELECT '2' UNION SELECT '3' UNION SELECT '4' UNION SELECT '5' UNION SELECT '6' ) AS b ON 1
) AS b,
( SELECT @i := - 1 ) AS i
评论区