日期:2014-05-16 浏览次数:22055 次
create table COL_TO_ROW
(
COL1 VARCHAR2(20),
COL2 VARCHAR2(20)
)
insert into col_to_row values('A','1');
insert into col_to_row values('A','12');
insert into col_to_row values('B','2');
insert into col_to_row values('B','23');
insert into col_to_row values('C','3');
insert into col_to_row values('C','334');
insert into col_to_row values('C','355')
select * from COL_TO_ROW
select col1,col2,row_number()over(partition by col1 order by col2)colnum from COL_TO_ROW
select col1,max(decode(colnum,1,col2,null))colA,max(decode(colnum,2,col2,null))colB,max(decode(colnum,3,col2,null))colC from (
select col1,col2,row_number()over(partition by col1 order by col2)colnum from COL_TO_ROW
)group by col1