oljo
oljo

Reputation: 59

SQL world table, need help to show continents with more than 10 countries

I am trying to learn sql and i have downloaded a world database. My problem is that i cannot find out how to pick the continents with more than 10 countries in them

My database is: name: (alle countries in the world) continent: (Africa, Americas, Asia-Pacific, Europe, Middle East, North America, South America, South Asia)

If someone can push me in the right direction, i would be really glad!

enter image description here

I know a part of what i need to do, but i am not sure where to put more code to get the result.

SELECT continent, COUNT(*)
FROM world
GROUP BY continent

I got the help i needed, thank you! The code i'm using is:

    SELECT continent, COUNT(*) 
    FROM world
    GROUP BY continent
    HAVING COUNT(name) > 10

Upvotes: 0

Views: 1957

Answers (1)

Liutprand
Liutprand

Reputation: 557

What you are missing is the HAVING statement that allows you to filter the results of an aggregation. (As opposed to the WHERE clause, that is executed before the rest of the query).

SELECT continent, COUNT(*)
FROM world
GROUP BY continent
HAVING COUNT(*)>10

Upvotes: 2

Related Questions