目标:生成前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"));
有关错误的任何建议都将受到高度赞赏。
答案 0 :(得分:0)
几个问题:
"MIN""
是一个拼写错误(额外"
)
.. As dbo_SO_SalesHistory.CustomerNo
, .
不是有效的列别名,以逃避它:.. As [dbo_SO_SalesHistory.CustomerNo]