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

1.List each country name where the population is larger than that of ‘Russia’.
world(name, continent, area, population, gdp)
SELECT name FROM world
WHERE population >
(SELECT population FROM world
WHERE name='Russia')
2.Show the countries in Europe with a per capita GDP greater than ‘United Kingdom’.
SELECT name FROM world
WHERE continent = 'Europe' AND name IN
(SELECT name FROM world
WHERE gdp/population >
(SELECT gdp/population FROM world WHERE name = 'United Kingdom' ) )
3.List the name and continent of countries in the continents containing either Argentina or Australia. Order by name of the country.
SELECT name,continent FROM world
WHERE continent IN

本文通过一系列SQL查询示例,详细解析如何在查询中使用子查询来执行更复杂的数据库操作,包括筛选人口超过俄罗斯的国家、找出欧洲人均GDP高于英国的国家、按面积查找各大洲的最大国家等。这些例子涵盖了从基础的子查询到高级的ALL和IN关键字的用法,是提升SQL技能的好资料。
最低0.47元/天 解锁文章
344

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



