答案 0 :(得分:1)
使用条件逻辑。这是一种方法:
select column1,
(case when sum(case when column2 = 'C' then 1 else 0 end) > 0
then 1
end) as has_c,
(case when sum(case when column2 = 'C' then 1 else 0 end) = 0
then 1
end) as does_not_have_c,
from table1 t1
group by column1;
或更简单地说是:
select column1,
max(case when column2 = 'C' then 1 end) as has_c,
min(case when column2 = 'C' then 0 else 1 end) as does_not_have_c,
from table1 t1
group by column1