答案 0 :(得分:1)
您可以进行有条件的聚合:
select anumber,
sum(tsp = 'aplace') as aplace,
sum(tsp = 'bplace') as bplace,
sum(tsp = 'cplace') as cplace
from table t
group by anumber;
答案 1 :(得分:1)
尝试使用CASE WHEN
select anumber,
sum(case when tsp = 'aplace' then 1 else 0 end) as aplace,
sum(case when tsp = 'bplace' then 1 else 0 end) as bplace,
sum(case when tsp = 'cplace' then 1 else 0 end) as cplace,
from table t
group by anumber;