group-byhaving-clause

Using sql group by and having


I'm quite new to SQL and I am trying to answer the exercise 8 of SQL ZOO, but I am missing something. Could you please help me?

List the continents that have a total population of at least 100 million.

What I am trying is:

select continent
from world
group by continent 
having count(population) >= 100000000

Solution

  • Your error was to use COUNT instead of SUM.

    Try the following:

    select continent
    from world
    group by continent
    having sum(population) >= 100000000