这两个查询可以被认为是相同的吗?

问题描述 投票:0回答:1

假设我有两张桌子顾客$,订单$。我想知道,因为这两个(下面给出)给出相同的结果。那么,我可以使用它中的任何一个或第二种方法代替内连接。

select Orders$.OrderDate,
       Customers$.ContactName
from Orders$
     inner join Customers$ on Orders$.CustomerID = Customers$.CustomerID;

select Orders$.OrderDate,
       Customers$.ContactName
from Orders$,Customers$
where Orders$.CustomerID = Customers$.CustomerID;

但是,当我正在解决一个问题 - https://www.hackerrank.com/challenges/average-population-of-each-continent/problem

所以两者都应该可以正常工作,但是第二个工作不正常,正如你在评论中所说的那样,两者都是一样的

select country.continent , round(avg(city.population -.5 , 0))  from country, city where country.code=city.countrycode group by country.continent;

select country.continent, round(avg(city.population - .5),0) from country inner join city on country.code=city.countrycode group by country.continent
sql-server join select syntax
1个回答
3
投票

这两个查询是等效的。虽然两者在技术上都是正确的,但现代语法鼓励使用显式连接,您应该坚持使用第一个变体。

© www.soinside.com 2019 - 2024. All rights reserved.