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,
vote_id vote
1 0
2 1
3 1
SELECT sum(vote) //output is 2
vote_id vote
1 -1
2 1
3 1
SELECT sum(vote) //output is 1, which is the desired output
I guess first off, my question is, is using 0, null, and 1 even make sense? Or should I should I just use -1, 0, 1?
Regardless, i’d be interested to know what the SQL query would look like to to sum up and down votes using 0, null, and 1.
I personally would use
-1,0and1.However,
0,NULLand1can also be made to work: