阅读(853)
赞(15)
MySQL 查看当月所有日期
2022-02-17 16:04:49 更新
select date from (
SELECT DATE_FORMAT(DATE_SUB(last_day(curdate()), INTERVAL xc-1 day), '%Y-%m-%d') as date
FROM (
SELECT @xi:=@xi+1 as xc from
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6) xc1,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6) xc2,
(SELECT @xi:=0) xc0
) xcxc) x0 where x0.date >= (select date_add(curdate(),interval-day(curdate())+1 day));
输出结果:
"date"
"2022-02-28"
"2022-02-27"
"2022-02-26"
"2022-02-25"
"2022-02-24"
"2022-02-23"
"2022-02-22"
"2022-02-21"
"2022-02-20"
"2022-02-19"
"2022-02-18"
"2022-02-17"
"2022-02-16"
"2022-02-15"
"2022-02-14"
"2022-02-13"
"2022-02-12"
"2022-02-11"
"2022-02-10"
"2022-02-09"
"2022-02-08"
"2022-02-07"
"2022-02-06"
"2022-02-05"
"2022-02-04"
"2022-02-03"
"2022-02-02"
"2022-02-01"