Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

SQL
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    
HiThe 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.

If you want to exclude 0 values also, then you have to provide this constraint in your query:
SQL
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
 
Share this answer
 
Hi,

Check this...

SQL HAVING Clause[^]

Hope this will help you.

Cheers
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900