Invalid Group function

From SQLZoo
Jump to navigation Jump to search


We want to filter the results returned based on an aggregate function such as COUNT or SUM.

The WHERE clause may not be used for this. The WHERE conditions are considered before the aggregation.


  • Put the condition into the HAVING clause, after the GROUP BY clause.
  • SELECT winner FROM nobel
      GROUP BY winner
      HAVING COUNT(winner)>1
SELECT winner FROM nobel
 WHERE COUNT(winner)>1
GROUP BY winner
DataWars, Data Science Practice Projects - LogoDataWars: Practice Data Science/Analysis with +100 Real Life Projects
Your server today is: digitalocean-sqlzoo