how in SQL to sum up (+1) and down (-1) votes using 1 and 0 values?

cravs

New Member
I realized this issue when trying to sum upvotes AND downvotes because the value of a downvote is -1 and not 0. This causes a problem when using the SQL sum() function. For example,\[code\]vote_id vote 1 0 2 1 3 1SELECT sum(vote) //output is 2vote_id vote 1 -1 2 1 3 1SELECT sum(vote) //output is 1, which is the desired output\[/code\]I guess first off, my question is, is using \[code\]0, null, and 1\[/code\] even make sense? Or should I should I just use \[code\]-1, 0, 1\[/code\]? Regardless, i'd be interested to know what the SQL query would look like to to sum up and down votes using \[code\]0, null, and 1\[/code\].
 
Top