MS-Access联合查询语法错误

时间:2017-11-01 16:19:22

标签: sql ms-access ms-access-2010 union

目标:生成前3位客户结果时,请在其中加入总和值

问题:联合查询中的语法错误

SELECT Sum(dbo_SO_SalesHistory.DollarsSold) AS SumDollarsSold, "ALLE" As dbo_SO_SalesHistory.CustomerNo  
FROM dbo_SO_SalesHistory 
WHERE ((dbo_SO_SalesHistory.[CustomerNo]) IN ("MIN","ALLE","BROO","OMP")) 
UNION
SELECT TOP 9  
Sum(DollarsSold), CustomerNo 
FROM dbo_SO_SalesHistory 
WHERE ((dbo_SO_SalesHistory.CustomerNo) NOT IN ("MIN"","BROO", "ALLE", "OMP")) GROUP BY dbo_SO_SalesHistory.CustomerNo ORDER BY 1 DESC;

因此,我测试每个单独的查询以确定哪个查询错误

查询的第一部分,给我

SELECT语句包含拼写错误或缺失的保留字或参数名称,或标点符号不正确。

SELECT Sum(dbo_SO_SalesHistory.DollarsSold) AS SumDollarsSold, "PHOALLE" As dbo_SO_SalesHistory.CustomerNo 
FROM dbo_SO_SalesHistory
WHERE ((dbo_SO_SalesHistory.CustomerNo) IN ("PHOMIN","PHOALLE","PHOBROO","PHOMP"));

有关错误的任何建议都将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

几个问题:

  • "MIN""是一个拼写错误(额外"

  • 由于.. As dbo_SO_SalesHistory.CustomerNo
  • .不是有效的列别名,以逃避它:.. As [dbo_SO_SalesHistory.CustomerNo]