我在名为data_tab
的表格中有以下数据sn code
2 101
2
2 202
5 103
5
5
如何查询在一行中查看结果,例如
sn code1 code2 code3
2 101 202
5 103
答案 0 :(得分:0)
嗨这给出了预期的输出......看看here
select sn,
max(decode(rn,1,code)) as CODE_1
,max(decode(rn,2,code)) as CODE_2
,max(decode(rn,3,code)) as CODE_3
from
(
select sn,
code,
row_number() over (partition by sn order by null ) rn
from test
)
group by sn