Link to home
Start Free TrialLog in
Avatar of Steve
SteveFlag for United States of America

asked on

SQL Query Help with SUM

How do I sum up the value of a given column for the rows that meet my query criteria, then return just the primary key of that column when that sum equals zero?
ASKER CERTIFIED SOLUTION
Avatar of tlayton
tlayton
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Patrick Matthews
If you mean to show the sum if non-zero, and nothing if the sum is zero...


SELECT ID, CASE WHEN SUM(OtherColumn) <> 0 THEN SUM(OtherColumn) ELSE NULL END AS Result
FROM SomeTable
GROUP BY ID

Open in new window

Avatar of Steve

ASKER

Um...yeah, you rock!  Thanks!
You're welcome, happy coding :)