SQLZOO练习三–SELECT within SELECT Tutorial

This tutorial looks at how we can use SELECT statements within SELECT statements to perform more complex queries.

namecontinentareapopulationgdp Afghanistan Asia 652230 25500100 20343000000 Albania Europe 28748 2831741 12960000000 Algeria Africa 2381741 37100000 188681000000 Andorra Europe 468 78115 3712000000 Angola Africa 1246700 20609294 100990000000 …

1、Bigger than Russia

获取人口比俄罗斯多的国家名字

List each country name where the population is larger than that of ‘Russia’.

2、Richer than UK

获取欧洲国家中,人均gdp高于United Kingdom的国家名称。

Show the countries in Europe with a per capita GDP greater than ‘United Kingdom’.

3、 Neighbours of Argentina and Australia

获取国家名称及所在大陆名称,条件是包含阿根廷或者澳大利亚的大陆,按照国家名称升序排序。

List the name and continent of countries in the continents containing either Argentina or Australia. Order by name of the country.

4、Between Canada and Poland

获取人口大于加拿大,同时人口小于波兰的国家名称、人口。

Which country has a population that is more than Canada but less than Poland? Show the name and the population.

5、Percentages of Germany

获取欧洲各国家名称,以及各国家人口/德国人口的百分比。

Germany (population 80 million) has the largest population of the countries in Europe. Austria (population 8.5 million) has 11% of the population of Germany.

Show the name and the population of each country in Europe. Show the population as a percentage of the population of Germany.

解题思路:1⃣️获取德国人口的select语句;2⃣️用concat函数,转换成字符串后拼接百分号。

6、Bigger than every country in Europe

获取超过欧洲任何一个国家gdp的国家名字。

Which countries have a GDP greater than every country in Europe? [Give the name only.] (Some countries may have NULL gdp values)

解题思路:超过欧洲任何一个国家gdp,这里用到聚合函数max(gdp),意思是取欧洲国家gdp的最大值。

7、 Largest in each continent

获取每个大洲面积最大的国家,展示所在大陆、国家名称、面积。

Find the largest country (by area) in each continent, show the continent, the name and the area:

8、 First country of each continent (alphabetically)

列出每个大洲以及按字母顺序排在第一位的国家/地区名称。

Find the continents where all countries have a population

解题思路:每个大洲全部国家人口都要小于2500万,用聚合函数max()函数。注意,这时候,不能用where,必须用having,因为where不能和聚合函数一起使用。

10、获取同一大洲,该国家面积大于等于其他所有国家3倍以上的国家名称和大洲名称。

Some countries have populations more than three times that of any of their neighbours (in the same continent). Give the countries and continents.

解题思路:

Original: https://www.cnblogs.com/ruoli-121288/p/16263563.html
Author: 徐若离
Title: SQLZOO练习三–SELECT within SELECT Tutorial

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/621706/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球