Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10 大的国家 #14

Open
astak16 opened this issue Jan 9, 2022 · 0 comments
Open

10 大的国家 #14

astak16 opened this issue Jan 9, 2022 · 0 comments
Labels

Comments

@astak16
Copy link
Owner

astak16 commented Jan 9, 2022

题目

编写一个 SQL 查询报告大国的国家名称、人口和面积。

满足下述任一条件之一,记为大国:

  • 面积至少为 300 万平方公里(3000000 km²)
  • 人口至少为 2500 万(25000000)
create table world (
	name varchar(255),
	continent varchar(255),
	area int,
	population int,
	gdp bigint
);

insert world values
('afghanistan', 'asia', 652230, 25500100, 2034000000),
('albania', 'europe', 28748, 2831741, 12960000000),
('algeria', 'africa', 2381741, 37100000, 188681000000),
('andorra', 'europe', 468, 78115, 3712000000),
('angola', 'africa', 1246700, 20609294, 100990000000);

SQL:方法一

select name, population, area from world where
area >= 3000000 or population >= 25000000;

解析

使用 or 连接两个条件

SQL

select name, population, area from world where area >= 3000000
union
select name, population, area from world where population >= 25000000;

解析

将两个条件分别查询,使用 union 将两次查询连接起来。

@astak16 astak16 added the 简单 label Jan 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant