我正在尝试从三个查询qryBOM
,qryLabour
和qryLaser
中提取总数,并将它们放在一行上。
我已经创建了一个qryTotals
过滤器,这是我的代码:
SELECT
Sum(tempTotalLabour) AS TotalLabour,
Sum(tempTotalCost) AS TotalCost,
Sum(tempTotalLaser) AS TotalLaser,
[TotalLabour] + [TotalCost] + [TotalLaser] AS ProductCost
FROM
(
SELECT
Sum([qryLabour].[Labour Mins]) AS tempTotalLabour,
Sum([qryLabour].[$ Cost]) AS tempTotalCost,
Sum([qryLabour].[Laser Mins]) AS tempTotalLabour
FROM
qryLabour
union all
SELECT
Sum([qryBOM].[Labour Mins]) AS tempTotalLabour,
Sum([qryBOM].[$ Cost]) AS tempTotalCost,
Sum([qryBOM].[Laser Mins]) AS tempTotaMaterial
FROM
qryBOM
union all
SELECT
Sum([qryLaser].[Labour Mins]) AS tempTotalLabour,
Sum([qryLaser].[$ Cost]) AS tempTotalCost,
Sum([qryLaser].[Laser Mins]) AS tempTotalLaser
FROM
qryLaser
) AS TotalTable;
但是我收到错误Duplicate Output Alias - 'tempTotalLabour'
。请有人可以帮助我解决我要去的地方,以便我可以解决此问题并为将来学习。
欢呼 克里斯
答案 0 :(得分:2)
您两次使用过tempTotalLabour
,如下所示进行了单次尝试
SELECT
Sum(tempTotalLabour) AS TotalLabour,
Sum(tempTotalCost) AS TotalCost,
Sum(tempTotalLaser) AS TotalLaser,
Sum(tempTotalLabour) + Sum(tempTotalCost) + Sum(tempTotalLaser) AS ProductCost
FROM
(
SELECT
Sum([qryLabour].[Labour Mins]) AS tempTotalLabour,
Sum([qryLabour].[$ Cost]) AS tempTotalCost,
Sum([qryLabour].[Laser Mins]) as tempTotalLaser
FROM
qryLabour
union all
SELECT
Sum([qryBOM].[Labour Mins]) AS tempTotalLabour,
Sum([qryBOM].[$ Cost]) AS tempTotalCost,
Sum([qryBOM].[Laser Mins]) AS tempTotalLaser
FROM
qryBOM
union all
SELECT
Sum([qryLaser].[Labour Mins]) AS tempTotalLabour,
Sum([qryLaser].[$ Cost]) AS tempTotalCost,
Sum([qryLaser].[Laser Mins]) AS tempTotalLaser
FROM
qryLaser
) AS TotalTable;