表包含以下列和数据:
Id | Date 1 | 04/09/2014 13:00:00 1 | 04/10/2014 15:00:00 1 | 04/12/2014 16:00:00 1 | 04/13/2014 18:00:00 2 | 04/11/2014 13:00:00 2 | 04/12/2014 15:00:00 2 | 04/12/2014 16:00:00
我需要为每个Id获取每个垂直对并将其转换为水平视图,结果应如下所示:
| ID | DATE1 | DATE2 | | 1 | April, 09 2014 13:00:00 | April, 10 2014 15:00:00 | | 1 | April, 10 2014 15:00:00 | April, 12 2014 16:00:00 | | 1 | April, 12 2014 16:00:00 | April, 13 2014 18:00:00 | | 1 | April, 13 2014 18:00:00 | (null) | | 2 | April, 11 2014 13:00:00 | April, 12 2014 15:00:00 | | 2 | April, 12 2014 15:00:00 | April, 12 2014 16:00:00 | | 2 | April, 12 2014 16:00:00 | (null) |
答案 0 :(得分:0)
试试这个:
select id, date date1, (select date
from data_table t2
where t2.ROWID>t1.ROWID and t2.date>t1.date and ROWNUM=1) date2
from data_table t1
我不是Oracle人员,在给定的解决方案中可能存在错误,您还需要根据需要格式化DATE
字段。