Grouping Data

SELECT
    Continent,
    Region,
    COUNT(*) AS CountriesCount,
    AVG(Population) AS AvgPopulation
FROM country
GROUP BY Continent, Region


Continent Region CountriesCount AvgPopulation
Asia Eastern Asia 8 188,416,000.00
Asia Middle East 18 10,465,594.44
Asia Southeast Asia 11 47,140,090.90
Asia Southern and Central Asia 14 106,484,000.00
Europe Baltic Countries 3 2,520,633.33
Europe British Islands 2 31,699,250.00
Europe Eastern Europe 10 30,702,600.00
Europe Nordic Countries 7 3,452,342.85
Europe Southern Europe 15 9,644,946.66
...

GROUP BY clauses can contain as many columns as you want. This enables you to nest groups, providing you with more granular control over how data is grouped.

Aside from the aggregate calculations statements, every column in your SELECT statement must be present in the GROUP BY clause.