我有简单的mysql表:
id server1 server2
1 Yes Yes
2 Yes No
3 No No
我要做的是计算每列中有多少“是”和“否”,然后在图表中使用该数字(如高图)
答案 0 :(得分:2)
select sum(server1 = 'Yes') as s1_yes,
sum(server2 = 'Yes') as s2_yes,
sum(server1 = 'No') as s1_no,
sum(server2 = 'No') as s2_no
from your_table
答案 1 :(得分:0)
像这样使用案例陈述
select server1,
sum(case when server1 = 'yes' then 1 else 0 end) as yes_count,
sum(case when server1 = 'no' then 1 else 0 end) as no_count
from yourtable