I have a query which returns the total number of votes (COUNT()) and the sum (SUM()) of all votes. A single vote is stored as a -1 or a 1.
Now I get the following and want to know what the number of positive votes is:
What is the formula to get the number of positive (and negative) votes?
In the example the outcome is: -1 + -1 + -1 + 1 (3 negative votes and 1 positive)
-x +y = sum
x + y = tot
=> 2y = sum + tot
=> y = (sum + tot)/2 ; x = tot - y
where y
is the number of positive votes and x
the negatives.
Or in more strong mathematical terms:
Why not just store negative as 0?
Positive would then be sum and negative would be total - sum.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.