将公司日历存储在数据库中,如下所示。请注意,公司日历从周六到周五开始:-
Date1 Week Month Quarter Year Shift
23-FEB-13 9 6 2 2013 ABC
23-FEB-13 9 6 2 2013 DEF
22-FEB-13 9 6 2 2013 ABC1
22-FEB-13 9 6 2 2013 DEF2
21-FEB-13 8 6 2 2013 DEF2
我想做的是创建一个视图来存储 Week#、StartWeek、EndWeek,即存储当前一周的开始和结束日期,例如
Week StartWeek EndWeek
9 22-FEB-13 23-FEB-13
这就是我到目前为止所拥有的
SELECT START_DATETIME, F_WEEK, ROW_NUMBER( ) OVER (PARTITION BY F_WEEK, F_YEAR ORDER BY SHIFT DESC) RNUM FROM COMMON.FISCAL_CALENDAR WHERE F_WEEK IN (SELECT F_WEEK FROM COMMON.FISCAL_CALENDAR WHERE TO_DATE(START_DATETIME, 'DD-MON-YY') = TO_DATE(SYSDATE, 'DD-MON-YY')) AND F_YEAR IN (SELECT F_YEAR FROM COMMON.FISCAL_CALENDAR WHERE TO_DATE(START_DATETIME, 'DD-MON-YY') = TO_DATE(SYSDATE, 'DD-MON-YY')) ORDER BY START_DATETIME DESC
如果有人可以对此进行更多说明,将不胜感激?