2013-03-05 158 views
1
-------------------------------------- 
code  Start DT End date Status 
-------------------------------------- 
Y68 25/OCT/11 25/OCT/11 ADM_CHECKD 
Y68 25/OCT/11 25/OCT/11 SATISFIED 
Y68 25/OCT/11 25/OCT/11 SATISFIED 
Y68 25/OCT/11 31/OCT/11 SATISFIED 
Y68   SATISFIED 

我的要求是,如果最後一行的開始日期爲空,它應該有值31/oct/11。這是上一行的結束日期值。填充空列的值基於另一列的先前值

在此先感謝。

+0

如何獲得最大結束日期並設置? – 2013-03-05 04:07:28

+1

是否要填充表格,或填充選擇查詢中的列? – AndrewP 2013-03-05 04:25:45

+0

當你說「前一行」時,你暗示有一個數據訂單。你是用'End Date'還是'Start DT'或其他列來訂購? – Wolf 2013-03-05 04:39:16

回答

1

如果您打算在前面一行是讓最後一排的結束日期排序爲來到代碼,你可以使用:

SQL> select code, 
    2   nvl(start_dt, lag(end_dt, 1) over (partition by code order by end_dt)) start_dt, 
    3   end_dt, status 
    4 from data 
    5 order by start_dt; 

COD START_DT END_DT STATUS 
--- --------- --------- ---------- 
Y68 28-FEB-13 01-MAR-13 ADM_CHECKD 
Y68 01-MAR-13 02-MAR-13 SATISFIED 
Y68 02-MAR-13 03-MAR-13 SATISFIED 
Y68 03-MAR-13 04-MAR-13 SATISFIED 
Y68 04-MAR-13   SATISFIED 

如: http://sqlfiddle.com/#!4/abe8f/1