Query
select companyname,sum(sale) as TotalSale,sum(purchase) as TotalPurchase from invoice group by companyname Having companyname IN (select companyname from invoice)
It returns sum only for those column whose all sum are not blank, how can i show blank sum values
I mean there are 7 companies but only 4 records are shown. I want to display all seven.
Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
I think you do not need the HAVING part of the SQL.
debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
Yes u are right as always.... But what about my problem....
Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
can u post some sample data.
debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
select companyname,sum(sale) as TotalSale,sum(purchase) as TotalPurchase from invoice group by companyname
I used the above query to get the total sale and purchase belong to following company
A , B ,C ,D ,E ,F ,G
only A,C,E,G have sale and purchase value other have no sale or purchase record.
so I got A 12 13 ,C 12 15 , E 15 89 , G 14 89 but i want rest company to show 0 if there sum of sale or purchase are not present.
Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
Following are the record
Company purchase sale
A 1 1
A 1 2
B 5 7
now the same above query will only show A and B company sale and purchase rest of companies values will be ignored and this is what i dont want.
Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
Let me clear it i m making report
Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
Please take my above query and place a outer join in correct manner....
Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
select companyname,sum(sale) as TotalSale,sum(purchase) as TotalPurchase from invoice group by companyname
I have already modified by query....
Also Nvl dont work.....
Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
100% Oracle Database...... :) I m making report which take all company name there purchase and sale SUMS and difference, some company can have no sale and purchase so atleast there name must be listed with 0 on both sale and purchase... Thats what all i want.
Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
NVL WORKED, but my problem isnt solved yet
Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
I agree with web-guy's earlier suggestion that you probably need to outer join your customer table to your invoice table for the sums. I assume that the customers who have no orders have no records in the invoice table. If they aren't in the table, they aren't going to appear in your group by results.
Try using [customer table] left outer join [invoice table] on the customer Ids.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847