I was trying to write a query that sort out product that had a sale more than $30, but kept getting the error "Error 1: could not prepare statement (1 near "Where": syntax error)"
SELECT ProductID, ProductName,SUM(Amount) as SUM
From Products
Group by ProductID, ProductName
Where Sum>=30;
GROUP BY
is supposed to come after WHERE
.
SELECT ProductID, ProductName, SUM(Amount) as SUM
FROM Products
WHERE Sum >= 30
GROUP BY ProductID, ProductName ;
从Product GROUP BY产品ID中选择ProductID,ProductName,SUM(Amount)作为总和,ProductName的sum(amount)> 30;
Use it like this:
SELECT ProductID, ProductName,SUM(Amount) as SUM
From Products Where SUM >= 30 Group by ProductID, ProductName;
Fixed, thanks everyone for help!
SELECT ProductID, ProductName, SUM(Price) FROM Products GROUP BY ProductID, ProductName Having Sum(Price) >= 30
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.