知识点
基础查询、常见运算符、like和%、round、length、left
数据表
world
题目内容
1.Read the notes about this table. Observe the result of running this SQL command to show the name, continent and population of all countries.(查询表中所有国家的名称、隶属洲、人口数量)
select name, continent, population from world
2.How to use WHERE to filter records. Show the name for the countries that have a population of at least 200 million. 200 million is 200000000, there are eight zeros.(查询人口数至少为200000000的国家)
select name from world
where population >= 200000000
3.Give the name and the per capita GDP for those countries with a population of at least 200 million.(查询人口数至少为200000000的国家和人均GDP,人均GDP=GDP/人口数)
select name,gdp/population from world
where population >= 200000000
4.Show the name and population in millions for the countries of the continent 'South America'. Divide the population by 1000000 to get population in millions.(查询隶属'South America'的国家和人口百万数,人口百万数=人口数/1000000)
select name,population/1000000 from world
where continent='south america'
5. Show the name and population for France, Germany, Italy. (查询'France, Germany, Italy'的国家和人口数)
select name,population from world
where name in ('France','Germany','Italy')
6.Show the countries which have a name that includes the word 'United'.(查询名称中含有'United'的国家)
select name from world
where name LIKE '%united%'
7.Two ways to be big: A country is big if it has an area of more than 3 million sq km or it has a population of more than 250 million.Show the countries that are big by area or big by population. Show name, population and area.(有两种方式定义大国:面积超过3000000平方千米或人口数超过250000000,查询面积大或人口多的国家、人口数和面积)
select name,population,area from world
where area >3000000 or population>250000000
8.Exclusive OR (XOR). Show the countries that are big by area (more than 3 million) or big by population (more than 250 million) but not both. Show name, population and area.(查询面积超过3000000平方千米或人口数超过250000000,但两者不能同时满足的国家、人口数和面积)
select name,population,area from world
where area >3000000 xor population>250000000
9.Show the name and population in millions and the GDP in billions for the countries of the continent 'South America'. Use the ROUND function to show the values to two decimal places.(查询隶属'South America'的国家、人口百万数和GDP十亿数,数字只保留2位小数)
select name,round(population/1000000,2),round(gdp/1000000000,2) from world
where continent = 'south america'
10.Show the name and per-capita GDP for those countries with a GDP of at least one trillion (1000000000000; that is 12 zeros). Round this value to the nearest 1000.(查询GDP至少1000000000000的国家和人均GDP,人均GDP精确到千分位)
select name,round(gdp/population,-3) from world
where gdp >= 1000000000000
11.Greece has capital Athens.Each of the strings 'Greece', and 'Athens' has 6 characters.Show the name and capital where the name and the capital have the same number of characters.(查询名称字母长度相同的国家和首都)
select name, capital from world
where length(name)=length(capital)
12.The capital of Sweden is Stockholm. Both words start with the letter 'S'.Show the name and the capital where the first letters of each match. Don't include countries where the name and the capital are the same word.(查询名称首字母相同的国家和首都,不包括国家名称和首都名称一样的情况)
select name,capital from world
where left(capital,1) = left(name,1)
and capital <> name
13.Equatorial Guinea and Dominican Republic have all of the vowels (a e i o u) in the name. They don't count because they have more than one word in the name.Find the country that has all the vowels and no spaces in its name.(查询名称中含有所有元音 (a e i o u),且不含空格的国家)
select name from world
where name like '%a%'
and name like '%e%'
and name like '%i%'
and name like '%o%'
and name like '%u%'
and name not like '% %';