Click here to Skip to main content
14,661,186 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hallo Experts,

I have done a mathematical equation based on columns and I want to only get the values < 10 and > 10. I have tried using Having but it isn't working. It still shows me the 0 values.

An Example;


Thnx

What I have tried:

SELECT DISTINCT 
 ProjectNr,
 SUM(GWVS) - SUM(GWVS2) AS GWValue1,
 SUM(ABVS) - SUM(GWVS2) AS GWValue2,
 SUM(TSVS) - SUM(GWVS2) AS GWValue2
FROM TBL1
WHERE RB IN (North)

GROUP BY ProjectNr

HAVING
SUM(GWVS) - SUM(GWVS2) <>10
Posted
Updated 25-Aug-16 19:22pm
Comments
F-ES Sitecore 25-Aug-16 11:36am
   
What "values" do you want to be <10 or >10? GWValue1 etc? Do you want those values included in the SUM and just not shown? Or do you want them included from the SUM?
mikybrain1 25-Aug-16 11:52am
   
Hi The values < or > 10 to be returned should be the one in the HAVING clause
Richard Deeming 25-Aug-16 11:44am
   
Hardly surprising that it's returning the 0 values, since 0 is less than 10! :)

Click "Improve question" and update your question with a clear and precise description of the problem.

Rate this:
Please Sign up or sign in to vote.

Solution 1

If you want to exclude 0 values also, then you have to provide this constraint in your query:
SELECT DISTINCT 
 ProjectNr,
 SUM(GWVS) - SUM(GWVS2) AS GWValue1,
 SUM(ABVS) - SUM(GWVS2) AS GWValue2,
 SUM(TSVS) - SUM(GWVS2) AS GWValue2
FROM TBL1
WHERE RB IN (North)
 
GROUP BY ProjectNr
 
HAVING
 (SUM(GWVS) - SUM(GWVS2)) <> 10
 AND (SUM(GWVS) - SUM(GWVS2)) <> 0
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi,

Check this...

SQL HAVING Clause[^]

Hope this will help you.

Cheers
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100