日期:2014-05-16  浏览次数:20502 次

行列置换oracle

?

?create table sale_list(
month varchar(6),
sell number(11,2)
);
insert into sale_list values('201101',1000);
insert into sale_list values('201102',2000);
insert into sale_list values('201103',3000);
insert into sale_list values('201104',4000);
insert into sale_list values('201105',5000);
insert into sale_list values('201106',6000);
commit;

?

 

?

DECODE(value, if1, then1, if2,then2, if3,then3, . . . else )

????? select

????  substrb(month,1,4),

????  sum(decode(substrb(month,5,2),'01',sell,0)) "1",
    sum(decode(substrb(month,5,2),'02',sell,0)) "2",