SQL 单列数据多条件求和显示在多列

我有个数据 A列 B列 C列
a X 3
a Y 4
b X 5
b Y 6
C X 7
C Y 8
我想得到的结果 对a b 的XY求和 分2列显示 结果如下
X Y
A 3 4
B 5 6
不用循环 并且数据量大的时候 也不会太卡. 因为我是用在vba里的 decode能不能用 我不是很清楚.如果答案中用到decode了 请帮忙确认下 excel VBA中是否可用.
我自己试着写过 是 select a列,(select sum(c列) as xsum from table where b列=x),(select sum(c列) as ysum from table where b列=y) from table group by a列.
也写过select a列,sum(decode(B列,X,c列,0)) as Xsum,sum(decode(B列,Y,c列,0)) as Ysum,from table group by a列. 但是都不能运行. 用循环写,实现效果了 但是用了10分钟运行时间.
求高手救命啊~!

A列:Acolumn
B列:Bcolumn
C列:Ccolumn
在数据库中,用 SQL,不过结果不是你那个格式
select Acolumn,Bcolumn,SUM(Ccolumn)
from table
where Acolumn in ('a','b') and Bcolumn in ('X', 'Y')
group by Acolumn,Bcolumn
温馨提示:答案为网友推荐,仅供参考
相似回答