MSAccess SQL查询-使用多个表合并所有表-重复字段
我试着从三个查询中提取总数,分别是MSAccess SQL查询-使用多个表合并所有表-重复字段,sql,ms-access,union-all,Sql,Ms Access,Union All,我试着从三个查询中提取总数,分别是qryBOM、qryLabour和qryLaser,并将它们列在一行 我已经创建了一个qryTotals过滤器,下面是我的代码: SELECT Sum(tempTotalLabour) AS TotalLabour, Sum(tempTotalCost) AS TotalCost, Sum(tempTotalLaser) AS TotalLaser, [TotalLabour] + [TotalCost] + [TotalLaser] AS Pr
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;
但是我得到了一个错误重复的输出别名-'testotallabour'
。请有人帮我解决哪里出了问题,这样我就可以解决这个问题,为将来学习
干杯
Chris您使用了两次
诱惑Totalabour
我做了一次,如下所示
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;
这不能是您正在运行以获取该错误消息的SQL。该错误指的是
templaboroutput
,它在查询中没有位置。请包含生成实际错误消息的实际查询。很抱歉,您是对的,我输入错误。你必须学会校对代码。除了明显的打字错误和拼写错误之外,这里没有任何问题。抱歉,我使用的是Access查询编辑器,所有内容都在一行中,我只是以上述方式进行格式化,以便于堆栈用户阅读-我应该加倍检查,因为我现在可以发现问题