表结构:
需要实现年月列倒置成行
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;
结果如下: