Subject | RE: [firebird-support] Join three tables problem |
---|---|
Author | Leyne, Sean |
Post date | 2014-11-27T21:35:07Z |
> i have triedThis is not a case where you want to use JOIN.
> select
> Seller.NameSeller,
> sum(buyfromseller.qty*buyfromseller.cost) as buys,
> sum(sell.qtysell*sell.price) as Sells,
> from
> Seller
> left join buyfromseller on buyfromseller.fkseller=seller.idseller
> left join sell on sell.fkseller=seller.idseller group by seller.nameseller
>
> but it turn me doubles values for the sell sum, how can i resolve it?
This is more what you want:
SELECT
Seller.NameSeller,
COALESCE( (SELECT SUM(buyfromseller.qty*buyfromseller.cost) FROM buyfromseller WHERE buyfromseller.fkseller=seller.idsellersum), 0) as buys,
COALESCE( (SELECT SUM(sell.qtysell*sell.price)) FROM Sell WHERE sell.fkseller=seller.idseller), 0) as Sells
FROM Seller
ORDER BY seller.nameseller