我正在编写一组类似的查询:
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
非常感谢! :)
答案 0 :(得分:2)
SELECT vote, count(users.id) AS `id` FROM users GROUP BY vote