我有一张桌子:

我想要像这样的东西:

在那里我计算了每种类型的工资。我知道我应该使用group by,但是它给了我一个行接一行的结果,并且我想把它放在单独的列中。我使用的是SQL。
提前谢谢。
发布于 2021-03-03 20:05:27
使用条件聚合:
select count(*),
sum(case when type = 'A' then salary end) as salary_a,
sum(case when type = 'B' then salary end) as salary_b,
sum(case when type = 'C' then salary end) as salary_c
from t;https://stackoverflow.com/questions/66456697
复制相似问题