0
我有一個事實表如下值:填充從季度日期的月日在甲骨文
As of Date F_Type Value
31-Mar-17 ABC Corp 1.0
30-Jun-17 ABC Corp 1.1
由於日期是季度結束日期,現在我需要編寫一個查詢得到的結果如下設置:(該值後的日期之間的月份結束日期被改變)
As of Date F_Type Value
31-Mar-17 ABC Corp 1.0
30-Apr-17 ABC Corp 1.0
31-May-17 ABC Corp 1.0
30-Jun-17 ABC Corp 1.1
我怎樣才能填充30-APR-17和31可能-17行?
代碼試圖至今:
SELECT
As_Of_Date,
F_Type,
Value,X.*
FROM FACT F INNER JOIN
(SELECT M_DATE,trunc(M_DATE+1,'Q')-1 AS QTR_DATE FROm
(Select TO_DATE('31-JAN-2017','DD-MON-YYYY') AS M_DATE from dual UNION ALL
Select TO_DATE('28-FEB-2017','DD-MON-YYYY') from dual UNION ALL
Select TO_DATE('31-MAR-2017','DD-MON-YYYY') from dual UNION ALL
Select TO_DATE('30-APR-2017','DD-MON-YYYY') from dual UNION ALL
Select TO_DATE('31-MAY-2017','DD-MON-YYYY') from dual UNION ALL
Select TO_DATE('30-JUN-2017','DD-MON-YYYY') from dual UNION ALL
Select TO_DATE('31-JUL-2017','DD-MON-YYYY') from dual UNION ALL
Select TO_DATE('31-AUG-2017','DD-MON-YYYY') from dual UNION ALL
Select TO_DATE('30-SEP-2017','DD-MON-YYYY') from dual UNION ALL
Select TO_DATE('31-OCT-2017','DD-MON-YYYY') from dual UNION ALL
Select TO_DATE('30-NOV-2017','DD-MON-YYYY') from dual UNION ALL
Select TO_DATE('31-DEC-2017','DD-MON-YYYY') from dual))X
ON F.As_Of_Date=X.QTR_DATE
這給了我類似下面:
As of Date F_Type Value M_Date Qtr_Date
3/31/2017 ABC Corp 1.0 3/31/2017 3/31/2017
3/31/2017 ABC Corp 1.0 4/30/2017 3/31/2017
3/31/2017 ABC Corp 1.0 5/31/2017 3/31/2017
6/30/2017 ABC Corp 1.1 6/30/2017 6/30/2017
6/30/2017 ABC Corp 1.1 7/31/2017 6/30/2017
6/30/2017 ABC Corp 1.1 8/31/2017 6/30/2017
有沒有辦法來調整這個查詢和輸出,以及。
可能你應該使用'last_day()'來確保生成的日期是月末,因爲30rh不是7月的最後一天。 – APC
我沒有粘貼來自我的數據庫的結果數據集,也許我手工編輯了它,我將更正答案。謝謝@APC讓我知道。假設數據將在月末結束,所以我使用了add_months,這使得下一個日期也是月份結束。 – kratostoical
謝謝@kratostoical –