Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I write a query there are three table and i used inner join and Group By method
Group are depend three type of GST
1) 0.00
2) 2.5
3) 9.00

i want to show only 2.5, and 9.00 how to hide the 0.00 pdgst
and show 5.00 in place of 2.5 and 18.00 in place of 9.00

Please Help me.....

What I have tried:

VB
select p.prtgst,p.prtynm,pr.invno,pr.invamt,PR.purinvdt,prd.pdcgst,sum(prd.totaltaxamt)As Rate,sum(prd.TaxableAmt)As Taxable_Amount
from TBL_pur_inv as pr
 INNER JOIN tbl_party_ldg  AS p   ON pr.partyIDpur = p.partyID
 INNER JOIN TBL_pur_invdet  AS prd   ON pr.purinvid = prd.purinvid
 
where purinvdt ='2018-01-04'  GROUP BY p.prtgst,p.prtynm,pr.invno,pr.invamt,PR.purinvdt,prd.pdcgst
Posted
Updated 6-Feb-18 9:38am

There isn't any rhyme or reason to your request, or at least none we can do as a generic solution based on that little data. Why is 0 to be ignored? That's easy to do:
SQL
SELECT ... WHERE ValueIDontWant != 0.0

But the rest? Why would one value be doubled, and the other halved? How many values does it apply to? All of them? Max and min? First and last? We don't know - and we can't work it out from your query because we have no idea what your tables or their data looks like.
And the query itself looks like you guessed, as I do not believe you really want to group by each of those columns. You do realise that each column you add to a GROUP BY increases the number of rows return, not reduces it, don't you?

Stop, sit down, look at your data tables and exactly what you are trying to return, and think about how everything relates before you start writing queries!
 
Share this answer
 
In addition to OriginalGriff's answer..

Take a look at the HAVING & WHERE clauses when used with GROUP BY - refer; Where Vs Having / Difference between having and Where clause [^]
The main difference is when the clauses are applied - Where is applied to the data prior to grouping, Having is applied after grouping - this allows you to use aggregate functions.

Kind Regards
 
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