2012-12-02 138 views
1

我正在寫一組查詢,像這樣多行:的MySQL數由where子句

SELECT count(users.id) AS `id` FROM users WHERE `vote` = 'cont6' 
SELECT count(users.id) AS `id` FROM users WHERE `vote` = 'cont7' 
SELECT count(users.id) AS `id` FROM users WHERE `vote` = 'cont8' 

我不知道如何/如果我能得到到一個查詢呢?所以我得到類似於以下的結果集:

cont6 = 12 
cont7 = 4 
cont8 = 15 

非常感謝! :)

回答

2
SELECT vote, count(users.id) AS `id` FROM users GROUP BY vote 
+0

真棒謝謝你! – sdm

+0

標記爲已接受的答案,如果幫助。 ;] – Gustek

+0

是的 - 有一個計時器阻止我馬上做它!全做完了! – sdm