MySQL 查看當(dāng)月所有日期

2022-08-04 17:14 更新
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)); 


輸出結(jié)果:

"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"


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號