Need sum if it is greater than zero, otherwise, return zero
Posted: Wed Nov 17, 2010 7:51 pm
Hey guys, it's been quite a while! I've taken some time off work to focus on a personal project of mine and I have run into a bit of a problem. I have a table called users_points that keeps track of a user's points in my app. Depending on certain actions they take on the site, they can score points and they can get points taken away (score negative points). So my table is basically a list of user IDs and a total of points scored for any particular action. Something like:
I need to sum up the total for each user, and if the sum is a positive number, then keep it, if it is a negative number, I need it to return zero. So with the above data I would need to return this:
Does anybody know how I might accomplish this? Thanks in advance!
P.S. I am going to try to post regularly again now that I have the time. So expect to see quite a bit more of me!
Code: Select all
user_id, total
1, 2
1, -2
4, 1
3, 5
4, -2
5, 1
Code: Select all
1, 0
4, 0
3, 5
5, 1
P.S. I am going to try to post regularly again now that I have the time. So expect to see quite a bit more of me!