表格:name continent population
China Asia 1300000000
... ... ...问题:
Find the largest country in each continent, show the continent, the name and the population:
答案:
SELECT continent, name, population FROM world x
WHERE population >= ALL
(SELECT population FROM world y
WHERE y.continent=x.continent
AND population>0)疑问:在这里设x和y表是什么意思?为什么最后还要加上population>0的条件?谢谢!
China Asia 1300000000
... ... ...问题:
Find the largest country in each continent, show the continent, the name and the population:
答案:
SELECT continent, name, population FROM world x
WHERE population >= ALL
(SELECT population FROM world y
WHERE y.continent=x.continent
AND population>0)疑问:在这里设x和y表是什么意思?为什么最后还要加上population>0的条件?谢谢!
我个人觉得这个population>0好像没多大必要,一般用处只是减少计算population=0的数据,减少计算范围,加快速度而已。
谢谢!我去复习一下自连接另外population>0我试过如果去掉的话,结果会少一行,不清楚是为什么原题来自这里的第六题:http://sqlzoo.net/wiki/SELECT_within_SELECT_Tutorial非常感谢!
All:对所有数据都满足条件,整个条件才成立,例如:5大于所有返回的id
select *
from #A
where 5>All(select id from #A)数据中population应该有<=0的