Subject | Join three tables problem |
---|---|
Author | |
Post date | 2014-11-27T18:26:51Z |
hi to all,
i have a problem i want join three tables, this is the structure (semplified)
Seller
IdSeller
NameSeller
BuyFromSeller
IdBuy
Qty
Cost
FkSeller
Sell
IdSell
QtySell
Price
FkSeller
i want know all the buy and the sell for seller (if there are)
i have tried
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?
thanks in advance.
i have a problem i want join three tables, this is the structure (semplified)
Seller
IdSeller
NameSeller
BuyFromSeller
IdBuy
Qty
Cost
FkSeller
Sell
IdSell
QtySell
Price
FkSeller
i want know all the buy and the sell for seller (if there are)
i have tried
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?
thanks in advance.