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。那是上一行的结束日期值。

提前致谢。

4

1 回答 1

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

于 2013-03-05T07:53:05.757 回答