左连接导致错误总和

时间:2012-08-24 05:11:47

标签: sql join sum

Suppl, fields: (Code_name, Code_name_arch, Tasknum, Pki_num, Group_eng, Name, Descr, Cost, Quan, shop)
Maker, fields : (Code_maker, Code_maker_arch, Code_name, provider)
Arrival, fields: (Code_arr, Code_maker, quan_arr)
Accounts, fields: (Code_acc, Code_maker, num_acc, quan_acc)  

我的查询是

select Name, Descr, Group_eng, 
Sum(quan_arr),
Sum(quan_acc) 
from [db_pki].[dbo].[Suppl] as deliveries
LEFT JOIN [db_pki].[dbo].[Maker] ON (deliveries.[Code_name] = [db_pki].[dbo].[Maker].[Code_name])
LEFT JOIN [db_pki].[dbo].[Arrival] ON ([db_pki].[dbo].[Maker].[Code_maker] = [db_pki].[dbo].[Arrival].[Code_maker])
LEFT JOIN [db_pki].[dbo].[Счета] ON ([db_pki].[dbo].[Maker].[Code_maker] = [db_pki].[dbo].[Accounts].[Code_maker])
where Group_eng = '501'
group by Name, Descr, Group_eng 
order by Name

Sum(quan_arr)和Sum(quan_acc)无法正常工作。我怎么能解决这个问题?

0 个答案:

没有答案