Using an aggregate function in where

后端 未结 2 1981
故里飘歌
故里飘歌 2021-01-18 09:21

I saw a few threads here with similar questions however I couldn\'t find something fitting my needs.

Consider the following table and example data:

CRE         


        
相关标签:
2条回答
  • 2021-01-18 09:50

    try it with the "having" clause!

    SELECT a,
       SUM(b) FROM foo
    GROUP BY a having sum(b) > 9;
    
    0 讨论(0)
  • 2021-01-18 09:52

    You can't use aggregate expression in the where clause - this is what the having clause is for:

    SELECT   a, SUM(b)
    FROM     foo
    GROUP BY a
    HAVING   SUM(b) > 9
    
    0 讨论(0)
提交回复
热议问题