1.Show the total population of the world.
world(name, continent, area, population, gdp)
SELECT SUM(population)
FROM world
2.List all the continents - just once each.
SELECT distinct(continent)
from world;
3.Give the total GDP of Africa
select sum(gdp)
from world
where continent='Africa';
4.How many countries have an area of at least 1000000
select count(name)
from world
where area>=1000000;
5.What is the total population of (‘Estonia’, ‘Latvia’, ‘Lithuania’)
select sum(population)
from world
where name in ('Estonia', 'Latvia', 'Lithuania');
6.For each continent show the continent and number of countries.
select continent,count(name)
from world
group by continent;
7.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>=10000000
group by continent;
8.List the continents that have a total population of at least 100 million.
select continent
from world
group by continent
having sum(population)>=100000000;

本文详细介绍了使用SQL进行数据查询的多种技巧,包括世界人口总览、各洲GDP汇总、特定区域人口统计等,通过具体示例展示了如何高效地从数据库中提取所需信息。
243

被折叠的 条评论
为什么被折叠?



