I realized this problem by trying to sum upvotes AND downvotes because the downvote value is -1 rather than 0. This causes a problem when using the sum () SQL function. For instance,
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, firstly, my question is, 0, null, and 1does use even make sense? Or should I just use -1, 0, 1?
Regardless, I would be interested to know what the SQL query would look like to summarize and down votes using 0, null, and 1.
source
share