答案 0 :(得分:2)
您可以使用聚合和case
:
select col1, max(col2) as col2,
(case when count(*) = count(col2) then 1 else 0 end) as col3
from t
group by col1;
如果你想要不可思议,你可以在没有case
:
select col1, max(col2) as col2,
(1 - sign(count(*) - count(col2))) as col3
from t
group by col1;