SQL语句复习
1. select 基础 (=, >, in , between and)
world表结构为:
name | continent | area | population | gdp |
---|---|---|---|---|
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 |
.... |
name:国家名称
continent:洲份
area:面积
population:人口
gdp:国内生产总值
1. 显示德国的人口:
select popilation from world where name = "Germany";
2. 查询面积为5,000,000以上平方公里的国家, 对每个国家显示她的名字和人均生产总值:
select name, gdp/population from world where area > 5000000;
3. 显示"lreland"爱尔兰, "lceland”冰岛, "Denmark"丹麦的国家名称和人口
select name, population from world where name in ("Ireland", "Iceland", "Denmark");
4. 显示面积为200,000及250,000之间的国家名称和该国面积
select name, area from world where area between 200000 and 250000;
总结:
判断结果是否在某几个值中的其中一个时, 使用
in ()
小括号的方法;判断结果是否在某个区间时, 使用
betwween
第一个值and第二个值的方法;