简体   繁体   中英

Can I use the result of a SUM function in the WHERE clause of SQL?

For example suppose I have

SELECT sum(...) as total

Can I do something like

WHERE total > 10

When I try that actual syntax I get an error unknown column 'total' in 'where clause' using MySQL

对于涉及聚集的条件,请使用HAVING而不是WHERE

SELECT SUM(somecolumn) AS total FROM sometable HAVING total > 10;

尝试HAVING

HAVING total > 10 

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM