Column1 Column2 Column3
Row1 x1 x2 y2
Row2 y1 y2 z2
Row3 z1 z2 (next row4 column2.value)
我正在尝试获取一个SQL查询,在此我要从row2.column2打印column3
答案 0 :(得分:3)
我认为您需要LAG
:
SQL> with test (id, col1, col2, col3) as
2 (select 1, 'x1', 'x2', null from dual union all
3 select 2, 'y1', 'y2', null from dual union all
4 select 3, 'z1', 'z2', null from dual
5 )
6 select id, col1, col2, lead(col2) over (order by id) col3
7 from test
8 order by id;
ID COL1 COL2 COL3
---------- ---- ---- ----
1 x1 x2 y2
2 y1 y2 z2
3 z1 z2
SQL>
我已经包含了ID
列,因为您必须要有一些排序行的依据。不必是ID
,也可以是某个日期值或其他任何值。