|
SELECT [%$##@_Alias].VIP卡, Sum([%$##@_Alias].表1分值之计数) AS 刷卡次数分值1, Sum([%$##@_Alias].表1分值之总计) AS 分值1, Sum([%$##@_Alias].表2分值之计数) AS 刷卡次数分值2, Sum([%$##@_Alias].表2分值之总计) AS 分值2, Sum([表2分值之总计]+[表1分值之总计]) AS 总分
FROM [SELECT 表2.VIP卡, Count(表2.分值) AS 表1分值之计数, Sum(表2.分值) AS 表1分值之总计,0 AS 表2分值之计数, 0 AS 表2分值之总计
FROM 表2
GROUP BY 表2.VIP卡
UNION SELECT 表3.VIP卡, 0 AS 表1分值之计数, 0 AS 表1分值之总计,Count(表3.分值) AS 表2分值之计数, Sum(表3.分值) AS 表2分值之总计
FROM 表3
GROUP BY 表3.VIP卡]. AS [%$##@_Alias]
GROUP BY [%$##@_Alias].VIP卡;
把“表3”变为“表1”就可以了 |
|