littlefat945 2021-09-12 15:00 采纳率: 70%
浏览 23
已结题

sql练习题疑问,对限定条件不太搞得懂

给定一个表

img

问题: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 否则输出的结果就是为空的呢?

原题的链接在

位置是在第十题

  • 写回答

1条回答 默认 最新

  • 急速光粒 2021-09-12 15:57
    关注

    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 ,那就包括他自己(他自己的人口怎么会大于他自己人口的三倍),就没有记录了。
    如有帮助请采纳!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月24日
  • 已采纳回答 9月16日
  • 创建了问题 9月12日

悬赏问题

  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Linux权限管理相关操作(求解答)
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表
  • ¥15 DbVisualizer Pro 12.0.7 sql commander光标错位 显示位置与实际不符
  • ¥15 android 打包报错
  • ¥15 关于stm32的问题