您可以使用条件聚合:
select group,
sum(case when location = 'A' then 1 else 0 end) as a,
sum(case when location = 'B' then 1 else 0 end) as b,
sum(case when location = 'C' then 1 else 0 end) as c
from t
group by group;
请注意,group
对于列而言是非常差的名称,因为它是SQL保留字。