我正在尝试将前一周的日期更新为当前日期,而在或> =之间的日期似乎在这里无效。
WITH curr_cyc_dt AS (
SELECT BETWEEN TO_DATE ('20181228', 'yyyymmdd') AND TO_DATE ('20190104', 'yyyymmdd') cyc_dt
FROM DUAL
)
答案 0 :(得分:0)
BETWEEN不能那样工作,它不会自动为您生成日期列表。这是一个比较运算符,用于检查日期是否属于日期间隔。
生成过去7天(直到今天为止)的天数列表的最简单方法:
WITH curr_cyc_dt AS (
SELECT
CURDATE(),
DATE_SUB(CURDATE(), INTERVAL 1 DAY),
DATE_SUB(CURDATE(), INTERVAL 3 DAY),
DATE_SUB(CURDATE(), INTERVAL 4 DAY),
DATE_SUB(CURDATE(), INTERVAL 5 DAY),
DATE_SUB(CURDATE(), INTERVAL 6 DAY),
DATE_SUB(CURDATE(), INTERVAL 7 DAY)
)
...
PS:FROM DUAL在MySQL中是多余的
答案 1 :(得分:0)
set @myDate = CURDATE();
set @rowNumber = 0;
select date_sub(@myDate, interval @rowNumber day),
(@rowNumber := @rowNumber + 1) as rownum
from information_schema.columns
LIMIT 7;