select isnull(isnull(a.userID,b.userID),c.userid) userID,isnull(isnull(a.[year],b.[year]),c.[year]) [year],a.pay1,b.pay2,c.pay3 from A区消费单 a full join B区消费单 b on a.userID=b.userID and a.[year]=b.[year] full join C区消费单 c on a.userID=c.userID and a.[year]=c.[year]
SELECT ISNULL(a.userId, ISNULL(c.userId, b.userId)) AS userID, ISNULL(a.[year],
ISNULL(c.[year], b.[year])) AS year, a.pay1, b.pay2, c.pay3
FROM dbo.bb b FULL OUTER JOIN
dbo.cc c ON b.userId = c.userId AND b.[year] = c.[year] FULL OUTER JOIN
dbo.aa a ON c.[year] = a.[year] AND c.userId = a.userId AND b.userId = a.userId AND
b.[year] = a.[year]
select isnull(a.userID,b.userID) userID,isnull(a.[year],b.[year]) [year],a.pay1,b.pay2 from A区消费单 a full join B区消费单 b on a.userID=b.userID and a.[year]=b.[year]
select userID,[year],sum(pay1) pay1,sum(pay2) pay2 from (
select userID,[year],pay1,null pary2 from A区消费单
union all
select userID,[year],null pay1,pary2 from B区消费单) tem group by userID,[year]
select userID,[year],sum(pay1) pay1,sum(pay2) pay2 from (
select userID,[year],pay1,null pary2 from A区消费单
union all
select userID,[year],null pay1,pary2 from A区消费单) tem group by userID,[year]