答案 0 :(得分:1)
使用select SUM(case when op1 = 'good' then 1 else 0 end) +
SUM(case when op2 = 'good' then 1 else 0 end) +
SUM(case when op3 = 'good' then 1 else 0 end) +
SUM(case when op4 = 'good' then 1 else 0 end) +
SUM(case when op5 = 'good' then 1 else 0 end) +
SUM(case when op6 = 'good' then 1 else 0 end)
from tablename
返回1表示正常,0表示其他值。对每列求和,将这些总和加在一起。
select op, count(*)
from
(
select op1 as op from tablename
union all
select op2 from tablename
union all
select op3 from tablename
union all
select op4 from tablename
union all
select op5 from tablename
union all
select op6 from tablename
) as t
group by op
可替换地:
{{1}}