1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| 1、先查看表结构 root@localhost:world > desc city; +-------------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+----------+------+-----+---------+----------------+ | ID | int(11) | NO | PRI | NULL | auto_increment | | Name | char(35) | NO | | | | | CountryCode | char(3) | NO | MUL | | | | District | char(20) | NO | | | | | Population | int(11) | NO | | 0 | | +-------------+----------+------+-----+---------+----------------+
root@localhost:world > desc country; +----------------+---------------------------------------------------------------------------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+---------------------------------------------------------------------------------------+------+-----+---------+-------+ | Code | char(3) | NO | PRI | | | | Name | char(52) | NO | | | | | Continent | enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') | NO | | Asia | | | Region | char(26) | NO | | | | | SurfaceArea | float(10,2) | NO | | 0.00 | | | IndepYear | smallint(6) | YES | | NULL | | | Population | int(11) | NO | | 0 | | | LifeExpectancy | float(3,1) | YES | | NULL | | | GNP | float(10,2) | YES | | NULL | | | GNPOld | float(10,2) | YES | | NULL | | | LocalName | char(45) | NO | | | | | GovernmentForm | char(45) | NO | | | | | HeadOfState | char(60) | YES | | NULL | | | Capital | int(11) | YES | | NULL | | | Code2 | char(2) | NO | | | | +----------------+---------------------------------------------------------------------------------------+------+-----+---------+-------+
root@localhost:world > desc countrylanguage; +-------------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+---------------+------+-----+---------+-------+ | CountryCode | char(3) | NO | PRI | | | | Language | char(30) | NO | PRI | | | | IsOfficial | enum('T','F') | NO | | F | | | Percentage | float(4,1) | NO | | 0.0 | | +-------------+---------------+------+-----+---------+-------+
2、#查询世界上小于100人的人口城市是哪个国家的? 找到你要的字段 国家 城市 城市人口数 country.name city.name city.population
select country.name,city.name,city.population from country,city where city.countrycode=country.code and city.population<100; +----------+-----------+------------+ | name | name | population | +----------+-----------+------------+ | Pitcairn | Adamstown | 42 | +----------+-----------+------------+
select country.name as 国家名,city.name as 城市名,city.population as 城市人口数量 from country,city where city.countrycode=country.code and city.population<100; +-----------+-----------+--------------------+ | 国家名 | 城市名 | 城市人口数量 | +-----------+-----------+--------------------+ | Pitcairn | Adamstown | 42 | +-----------+-----------+--------------------+
3、#查询世界上小于100人的人口城市是哪个国家的说的什么语言? 找到你要的字段 国家 城市 城市人口数 语言 country.name city.name city.population countrylanguage.language
select country.name,city.name,city.population,countrylanguage.language from city,countrylanguage,country where city.countrycode=country.code and country.code=countrylanguage.countrycode and city.population<100; +----------+-----------+------------+-------------+ | name | name | population | language | +----------+-----------+------------+-------------+ | Pitcairn | Adamstown | 42 | Pitcairnese | +----------+-----------+------------+-------------+
|