1、兩個字段表,id和name,其中id和name一對多關(guān)系,需要列轉(zhuǎn)行操作:
create table test(id number, name varchar2(20));
insert into test values(1, 'a');
insert into test values(2, 'b');--添加多條數(shù)據(jù),一對多
select tmp.id,
max(decode(tmp.row_number, 1, name)) as c1,
max(decode(tmp.row_number, 2, name)) as c2,
max(decode(tmp.row_number, 3, name)) as c3,
max(decode(tmp.row_number, 4, name)) as c4,
max(decode(tmp.row_number, 5, name)) as c5
from (select t.*, row_number() over(partition by t.id order by name) as row_number from test t) tmp
group by tmp.id

缺點:1對n,需要添加n個max行,少量的統(tǒng)計可以這樣做。
2、行轉(zhuǎn)列,將n個字段通過字符連接成一個字段進(jìn)行展示:
oracle 12g通過listagg函數(shù)實現(xiàn),可自行百度。
浙公網(wǎng)安備 33010602011771號