mysql - MYSQL:通过连接几个表来查询世界数据库
问题描述
问题是:
给出 SQL 命令以显示北美的每个国家:
- 首都名称
- 国家名称
- 官方语言
- 说官方语言的人的百分比
结果应按城市名称字母顺序排列,在该范围内按国家名称顺序排列,在该范围内按语言顺序排列,在该范围内按百分比升序排列。获取错误消息不是唯一的表别名国家。
SELECT
city.name AS name, country.name AS name,
countrylanguage.language,
countrylanguage.percentage
FROM country, countrylanguage, city
INNER JOIN country ON city.countrycode = country.code
INNER JOIN city ON country.capital = city.id
INNER JOIN countrylanguage on country.code = countrylanguage.countrycode
WHERE
country.continent = 'North America' and
countrylanguage.isofficial = 'T' and
country.capital = city.id
ORDER BY
city.name ASC,
country.name,
country.language,
countrylanguage.percentage ASC;
解决方案
您的FROM ... JOIN
查询部分不正确。尝试这个。
SELECT
city.name AS name, country.name AS name,
countrylanguage.language,
countrylanguage.percentage
FROM country
INNER JOIN country ON city.countrycode = country.code
INNER JOIN city ON country.capital = city.id
INNER JOIN countrylanguage on country.code = countrylanguage.countrycode
WHERE
country.continent = 'North America' and
countrylanguage.isofficial = 'T' and
country.capital = city.id
ORDER BY
city.name ASC,
country.name ASC,
country.language ASC,
countrylanguage.percentage ASC;
当你说它FROM country, city, countrylanguage
相当于上面的代码但没有ON
子句时。这是老式的逗号连接语法(在 1992 年被显式 JOIN 语法取代)。
推荐阅读
- python - python-pptx:从幻灯片中提取文本时出现奇怪的拆分
- autodesk-forge - 如何为特定的 dbId 设置独立的材料
- android - 工具栏中的进度条未在android中显示
- php - 在 PHP 中,POST 方法最多可以设置多少内存限制?最大多少?
- bash - 用于移动文件的 BASH 脚本未正确移动文件
- php - 在 Headers From 字段中使用 Php 变量
- python - 如何转换具有主文本和多个子文本的字典
- matlab - 如何计算图 MatLab 的所有节点之间的距离
- javascript - JQuery .css 不能在 if 语句中使用 margin-left
- java - 如何实现其通用模板扩展另一个接口的通用接口?