I have been struggling with the following problem for a long time.
I have an experience table like this
id | uid | positive | negative
开发者_C百科uid
- gains the experience
positive
- is the experience positive?
negative
- is the experience negative?
The user table look like this
id | username | password
But how can I count the net experience for a user? How can I determine if the net experience is positive or negative with a query?
SELECT uid, SUM(positive - negative) AS NetExp
FROM experience
GROUP BY uid
This shows you the net experience per user. What do you mean with collect it?
It would be better to have experience as a single column and add to it and subtract from it as necessary, rather than two columns to store one number. A query that would work in your case now though would be:
SELECT `uid`, (`positive`-`negative`) as exp FROM `experience`
精彩评论