我看过这篇文章(SQL - Query to seperate single column and create new columns based on column data)并希望对此发表评论,但是,我没有足够的代表。我想做同样的事情,但我想总结为case语句创建的列中的值。
答案 0 :(得分:2)
您可以对这样的案例(假设列名称)应用总和:
select
name,
sum(case when status = 'A' then value end) SUM_A,
sum(case when status = 'B' then value end) SUM_B,
sum(case when status = 'C' then value end) SUM_C,
sum(case when status = 'D' then value end) SUM_D
from your_table
group by name;