如何計算具體的話我有簡單的MySQL表:使用PHP和MySQL
id server1 server2
1 Yes Yes
2 Yes No
3 No No
我試圖做的是計算有多少「是」和「否」的每列中,然後用在圖表,數字(如highcharts)
如何計算具體的話我有簡單的MySQL表:使用PHP和MySQL
id server1 server2
1 Yes Yes
2 Yes No
3 No No
我試圖做的是計算有多少「是」和「否」的每列中,然後用在圖表,數字(如highcharts)
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
非常感謝,謝謝! – user1060641
使用case語句這樣
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
請告訴我們你的企圖。 – ComFreek
這似乎違反了[零,一個或無限規則](http://en.wikipedia.org/wiki/Zero_one_infinity_rule)。像「server1」和「server2」這樣的列通常是數據未正確[標準化]的標誌(http://en.wikipedia.org/wiki/Database_normalization)。 – tadman
可能的重複[如何calcual word和輸出結果在php](http://stackoverflow.com/questions/19599263/how-to-calcualte-number-of-word-and-output-result-in- php) – andrewsi