Issue
Im looking for a way that I can get candidates result in a voting session.
See Image above. Candidate Id 5 has been voted in by 3 voters, making it 3 votes. Candidate Id 4 has been voted in by 1 voter, making it 1 vote.
So candidate Id 5 wins by 3 votes against Candidate Id 4 with 1 vote.
I need a query that can group this results by department eg. hospital, and show the candidates with their respective votes count in order from top to last candidate
Solution
select count(voter_ID) as votecount, candidate_id from tablename group by candidate_id, position order by votecount
You can group by two column like candidate_id and position.
Answered By - Raj Hirani