사람투표
오바마
매케인 아니
오바마
오바마 아니
매케인
오바마
오바마
오바마 아니
매케인 아니

http://www.randomsnippets.com/2008/10/05/how-to-count-values-with-mysql-queries/

SELECT person, 
SUM(IF(vote = "yes", 1,0)) AS `yes_votes`, 
SUM(IF(vote = "no", 1,0)) AS `no_votes`, 
COUNT(vote) AS `total` 
FROM votes 
GROUP BY person 
ORDER BY yes_votes DESC 

다음은 쿼리의 결과 것입니다 :

사람YES_VOTESNO_VOTES합계
오바마 4 2 6
매케인 1 2 3
Posted by [czar]
,