-1

我有简单的mysql表:

id  server1   server2
1      Yes      Yes
2      Yes      No
3      No       No

我要做的是计算每列中有多少“是”和“否”,然后在图表中使用该数字(如 highcharts)

4

2 回答 2

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
于 2013-10-25T18:21:40.153 回答
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
于 2013-10-25T18:28:37.793 回答