行列倒置(二)----交叉表(oracle)

来源:互联网 发布:网络作家收入如何 编辑:程序博客网 时间:2024/06/03 23:45

表结构:

 

需要实现年月列倒置成行

 

select column1,sum(case when substr(syear,5,2)='01' then smoney end) as 一月,
sum(case when substr(syear,5,2)='02' then smoney end) as 二月,
sum(case when substr(syear,5,2)='03' then smoney end) as 三月,
sum(case when substr(syear,5,2)='03' then smoney end) as 四月
from sellmoney group by column1;

 

select column1,sum(decode(substr(syear,5,2),'01',smoney)) as 一月,
sum(decode(substr(syear,5,2),'02',smoney)) as 二月,
sum(decode(substr(syear,5,2),'03',smoney)) as 三月,
sum(decode(substr(syear,5,2),'04',smoney)) as 四月
from sellmoney group by column1;

 

结果如下:

 

0 0