我想連接四個表使用關節,在這裏我用左連接來連接表和我的條件是所有的商品,項目應該是相同的,所有的網站應該是same.same網站有多件商品,所以我想從每張桌子上得到商品的總數。我的查詢給出與多個連接和條件的Mysql查詢
select
a.goods
,sum(a.no_of_units) as totala
, a.site
,b.item
,sum(b.quantity) as totalb
,b.site
,c.goods
,c.site
,sum(c.no_of_units) as totalc
,d.site
,d.goods
,sum(d.quantity)b as totald
from
inward_stock a
left join
opening_balance b
on
a.site=b.site
and
a.goods=b.item
left join
return_stock c
on
b.site=c.site
and
b.item=c.goods
left join
stock_consumed d
on
d.site=c.site
and
d.goods=c.goods
在這裏提供架構,所以我們可以幫助你 – ddw147 2015-02-23 07:05:13
你忘了問一個問題。查詢不起作用嗎?它會給出錯誤嗎?錯誤的數據? – Mureinik 2015-02-23 07:08:01