We help IT Professionals succeed at work.

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

bootneck2222
bootneck2222 asked
on
472 Views
Last Modified: 2013-12-13
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
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

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

Open in new window

Author

Commented:
Thank you Louis01.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.