I have a table with fields user_id and votes. The votes field is either 1 for an up vote, or 0 for down vote.
What I’d like to do is display the total up votes and total down votes in one query for a specific user.
I was thinking I could maybe use GROUP BY somehow to achieve this, but I don’t know if I can use it with a SUM function somehow?
GROUP BYwould only be necessary if you wanted the vote count for multiple users; with a single user, one need only specify aWHEREclause:As an aside, you might want to consider having downvotes stored as
-1(instead of0) in order that the net vote count can easily be calculated as justSUM(votes).