The column alias isn't available in the HAVING
clause. (Just as specified by ANSI/ISO SQL.)
Either put the SUM()
in the HAVING
clause:
SELECT idproduct, SUM(quantity) AS amnt_sold
FROM [table]
GROUP BY idproduct
HAVING SUM(quantity) >= 3
Or, wrap the query up in a derived table, and then use the amnt_sold column name.
SELECT idproduct, amnt_sold
FROM
(
SELECT idproduct, SUM(quantity) AS amnt_sold
FROM [table]
GROUP BY idproduct
) dt
WHERE amnt_sold >= 3
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…