SQL学习日志-Day 1
SQL ZOO-Sum and count
1.For each continent show the continent and number of countries with populations of at least 10 million.
select continent, count(name)
from world
where population > 100000000
group by continent
可以看到,group by的语法顺序在where之后,后两句语句表达的意思实际是“先筛选人口数大于10000000的国家,再根据大陆板块将国家分类”
2.List the continents that have a total population of at least 100 million.
select continent
from world
group by continent
having sum(population) > 100000000
同样地,having的语法顺序在group by之后,后两句语句表达的意思实际是“先将国家依据大陆板块分组,再筛选每组总人口大于100000000的大陆”