还请高人指点写一个oracle的sqlyearmonthamount1991 11.11991 21.21991 31.31991 41.41992 12.11992 22.21
还请高人指点写一个oracle的sql
year month amount
1991 1 1.1
1991 2 1.2
1991 3 1.3
1991 4 1.4
1992 1 2.1
1992 2 2.2
1992 3 2.3
1992 4 2.4
需要的结果:
y m1 m2 m3 m4
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4
还请大虾帮忙呀!感激不尽!!!!!!!!!!
[解决办法]
11g以下的版本,写起来代码比较多:
select year y,
sum(decode(month, 1, amount)) m1,
sum(decode(month, 2, amount)) m2,
sum(decode(month, 3, amount)) m3,
sum(decode(month, 4, amount)) m4
from t
group by year
[解决办法]
第一次接触 挺好用的
