表 tblCountResults
**Columns**
Activity
MinOfName
CountOfActivity
表 tblCountResultsSQL
**Columns**
Activity
MinOfName
CountOfActivity
我需要的是将这两个表合并为一个。如果活动匹配,我需要将两个表中的 CountofActivity 添加在一起。无论是否匹配,我都需要保留 Activity 和 MinOfName 。
也许是这样,但我不确定如果同一活动有多个 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
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