在Access,Total 1 Column中合并2个类似的表并保持所有不匹配

时间:2013-11-12 21:43:18

标签: sql ms-access

表 tblCountResults

**Columns**
Activity
MinOfName
CountOfActivity

表 tblCountResultsSQL

**Columns**
Activity
MinOfName
CountOfActivity

我需要的是将这两个表合并为一个。如果活动匹配,我需要将两个表中的CountofActivity添加到一起。无论是否匹配,我都需要保留Activity和MinOfName。

2 个答案:

答案 0 :(得分:0)

也许是这样,但我不确定如果MinofName的多个属于同一个活动,将会如何处理......

Select coalesce(A.activity, B.Activity) as Activity, 
 coalesce(A.MinofName, B.MinofName) as MinOfName, 
 coalesce(A.countofActivity,0) + coalesce(b.CountofActivity) as SumofcountofActivty
FROM tblCountResults A Full outer Join tblCountResultsSQL B 
  ON A.Activity = B.Activity

答案 1 :(得分:0)

select isnull(t1.activity, t2.activity) as activity,
isnull(t1.MinOfName, t2.MinOfName) as MinOfName,
isnull(t1.CountOfActivity, 0) + isnull(t2.CountOfActivity, 0) as count
from tblCountResults t1
full outer join tblCountResultsSQL t2 on t2.activity = t2.activity