Goal : When generating a top 3 customer result, include a sum value in it
Problem : syntax error in union query
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;
So I test each individual query to pinpoint which query is wrong
The first part of query, gives me
The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
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"));
Any advice regarding the errors would be highly appreciated.
Couple of issues:
"MIN""
is a typo (extra "
)
.. As dbo_SO_SalesHistory.CustomerNo
is not a valid column alias due to the .
, to escape it: .. As [dbo_SO_SalesHistory.CustomerNo]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.