给定一个表
问题:Some countries have populations more than three times that of any of their neighbours (in the same continent). Give the countries and continents.
答案:select name,continent from world as y
where population > ALL
(select population*3 from world as x where
x.continent = y.continent
AND x.name <>y.name )
疑问:
为什么最后要给一个限定条件 AND x.name <>y.name 否则输出的结果就是为空的呢?
select name,continent from world as y
where population > ALL
(select population*3 from world as x where
x.continent = y.continent
AND x.name <>y.name )
这个sql意思是找出大于和他属于同一个大洲的其他国家的人口三倍的国家。如果你没有限定条件 AND x.name <>y.name ,那就包括他自己(他自己的人口怎么会大于他自己人口的三倍),就没有记录了。
如有帮助请采纳!