Re: sum, group by, union
Hi,
Since products may or may not have matching rows in the delivery and sell table, you need to use left joins. Also, since left joins will return NULLs for non-matching rows, you want to convert these to zeros using the ifnull function in your SELECT query.
try this.
select p.name, sum(ifnull(d.Count, 0)), sum(ifnull(s.Count, 0))
from TblProduct p
left join TblProductDelivery d on p.Number=d.ProductNumber
left join TblProductSell s on p.Number=d.ProductNumber
group by p.name;
Chris
Subject
Written By
Posted
Re: sum, group by, union
April 06, 2005 11:02AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.