Avatar of bootneck2222
bootneck2222 asked on

SQL syntax to count the number of rows where the sum of a column is equal or greater than a value

Hi,

I have a table that records points that users are awarded. A user can have multiple rows in a table as points are awarded at different times. I am trying to write a SQL statement that will count the number of users that have total points greater or equal to 12 points. For example:

User       Points      Date
John        2             2013-12-01
Adam      4             2013-12-02
Mike       6             2013-12-02
John              6             2013-12-04
Mike              8             2013-12-05
John          6             2013-12-06
 
So in this example the count would be 2 (John and Mike).

Any help would be greatly appreciated. Thank you
MySQL ServerSQL

Avatar of undefined
Last Comment
bootneck2222

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Louis01

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Argenti

select user, sum(points)
from mytable t
group by user
having sum(points) >= 12

Open in new window

ASKER
bootneck2222

Thank you Louis01.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy