MSAccess SQL 查询 - 将所有表与多个表合并 - 重复字段

MSAccess SQL Query - Union all with multiple tables - Duplicate field

我试图从三个查询 qryBOMqryLabourqryLaser 中获取总数,并将它们列在一行中。

我创建了一个 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'。请有人能帮我解决我哪里出错了,这样我就可以解决这个问题并为将来学习。

干杯 克里斯

你用了 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;