求一查询语句,请高手帮忙
表:
contno expcode amount
B00001 A1 100
B00001 A2 200
B00002 A2 400
B00002 A3 500
.............
我需要得到如下格式
Contno A1 A2 A3 ......
B00001 100 200
B00001 400 500
........
在线等
------解决方案--------------------select xxx.id, sum(xxx.A1),SUM(XXX.A2),SUM(XXX.A3)
from
(select contno ID,
amount A1 ,
0 A2,
0 A3
from tablename
where expcode =A1
unoin all
select contno ID,
0 A1 ,
amount A2,
0 A3
from tablename
where expcode =A2
union all
select contno ID,
0 A1 ,
0 A2,
amount A3
from tablename
where expcode =A3)xxx
group by xxx.id
------解决方案--------------------select contno,
sum(decode(expcode, 'A1 ',amount,0),
sum(decode(expcode, 'A2 ',amount,0),
sum(decode(expcode, 'A3 ',amount,0),
...
from table
group by contno