开发者

User experience count

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`
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜