我想为此“在给定的几年间隔内获得一年中每周的天数(星期一,星期二,网络,...,太阳)”找到所有解决方案
有人知道其他答案吗?请分享它;)
这是我的查询:)
WITH dat AS
(SELECT &&start_year + level - 1 cur_year, DECODE(MOD(&start_year + level - 1, 4), 0, 0, 1) no_leap,
TO_NUMBER(TO_CHAR(TO_DATE('01.01.'||TO_CHAR(&start_year + level - 1)), 'D')) d
FROM dual
CONNECT BY LEVEL < &end_year - &start_year + 2)
SELECT cur_year,
51 + DECODE(no_leap, 1, DECODE(d, 1, 2, 1), DECODE(d, 1, 2, 7, 2, 1)) mon,
51 + DECODE(no_leap, 1, DECODE(d, 2, 2, 1), DECODE(d, 2, 2, 1, 2, 1)) tue,
51 + DECODE(no_leap, 1, DECODE(d, 3, 2, 1), DECODE(d, 3, 2, 2, 2, 1)) wed,
51 + DECODE(no_leap, 1, DECODE(d, 4, 2, 1), DECODE(d, 4, 2, 3, 2, 1)) thu,
51 + DECODE(no_leap, 1, DECODE(d, 5, 2, 1), DECODE(d, 5, 2, 4, 2, 1)) fri,
51 + DECODE(no_leap, 1, DECODE(d, 6, 2, 1), DECODE(d, 6, 2, 5, 2, 1)) sat,
51 + DECODE(no_leap, 1, DECODE(d, 7, 2, 1), DECODE(d, 7, 2, 6, 2, 1)) sun
FROM dat;