开发者

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

开发者 https://www.devze.com 2023-02-13 04:35 出处:网络
For example suppose I have SELECT sum(...) as total Can I do something like WHERE total > 1开发者_JS百科0

For example suppose I have

SELECT sum(...) as total

Can I do something like

WHERE total > 1开发者_JS百科0

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


Use HAVING instead of WHERE for conditions involving aggregates:

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


Try HAVING

HAVING total > 10 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号