Search code examples
mysqlgroup-byaggregate-functionsmysql-error-1111

mysql use group by column in where condition


How can I make this query work :

SELECT column1.....,SUM(Hits) AS Hits   
FROM table 
WHERE  SUM(Hits) > 100
GROUP BY column1.....

The problem is the where clause, mysql display error :

Error Code : 1111
Invalid use of group function

I try to change the query to :

 SELECT column1.....,SUM(Hits) AS Hits   
    FROM table 
    WHERE  Hits > 100
    GROUP BY column1.....

It did not help.

thanks


Solution

  • SELECT column1.....,SUM(Hits) AS HitsSum 
    FROM table 
    GROUP BY column1.....
    HAVING HitsSum > 100