最近写了很多SQL,记录下
查询最近7天的日期,如 2022-08-12、2022-08-13、 ... 2022-08-18
Oracle写法
SELECT TO_CHAR ( SYSDATE - LEVEL + 1, 'YYYY-MM-DD' ) TIME FROM DUAL CONNECT BY LEVEL <= 7
MySQL写法
SELECT curdate() AS TIME UNION SELECT date_sub(curdate(), INTERVAL 1 DAY) AS TIME UNION SELECT date_sub(curdate(),
INTERVAL 2 DAY) UNION SELECT date_sub(curdate(), INTERVAL 3 DAY) UNION SELECT date_sub(curdate(), INTERVAL 4 DAY) UNION
SELECT date_sub(curdate(), INTERVAL 5 DAY) UNION SELECT date_sub(curdate(), INTERVAL 6 DAY) FROM DUAL
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏