gpt4 book ai didi

MYSQLWhere语句/子句被忽略

转载 作者:行者123 更新时间:2023-11-29 07:47:44 25 4
gpt4 key购买 nike

SELECT country.continent, country.name, city.district, city.name, city.population
FROM world.country, world.city
WHERE city.population < 3000000
LIMIT 20, 30;

我得到的是笛卡尔积,而不是显示 select 子句内容的表格,其中城市人口超过 300 万。

world是数据库的名称国家和城市是表

请帮忙。

最佳答案

您需要将表连接在一起:

SELECT country.continent, country.name, city.district, city.name, city.population
FROM world.country JOIN
world.city
ON country.code = city.countrycode
WHERE city.population < 3000000
LIMIT 20, 30;

作为编写 SQL 的提示:切勿在 from 子句中使用逗号。始终使用显式联接。这些比隐式联接更强大(许多人认为它们使查询更易于阅读和维护)。

关于MYSQLWhere语句/子句被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27261296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com