开发者

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 > 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜