mysql中any,in,some,all的区别
any 可以与=、>、>=、<、<=、<>结合起来使用,分别表示等于、大于、大于等于、小于、小于等于、不等于其中的任何一个数据。all可以与=、>、>=、<、<=、<>结合是来使用,分别表示等于、大于、大于等于、小于、小于等于、不等于其中的其中的所有数据。any,all关键字必须与一个比较操作符一起使用。any关键词可以理..
any 可以与=、>、>=、<、<=、<>结合起来使用,分别表示等于、大于、大于等于、小于、小于等于、不等于其中的任何一个数据。
all可以与=、>、>=、<、<=、<>结合是来使用,分别表示等于、大于、大于等于、小于、小于等于、不等于其中的其中的所有数据。
any,all关键字必须与一个比较操作符一起使用。any关键词可以理解为“对于子查询返回的列中的任一数值,如果比较结果为true,则返回true”。
not in 是 “<>all”的别名,用法相同。
语句in 与“=any”是相同的。
语句some是any的别名,用法相同。
举例:
sqlzoo里的题:
Which countries have a GDP greater than every country in Europe? [Give the name only.] (Some countries may have NULL gdp values)
答案:
select name from world where gdp>all(select gdp from world where continent='Europe' and gdp>0)
9.Find the continents where all countries have a population <= 25000000. Then find the names of the countries associated with these continents. Show name, continent and population.
select name, continent,population from world x where 25000000 >= all(select population from world y where x.continent=y.continent and area>0)
10.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 x where population>=all(select population*3 from world y where x.continent=y.continent and x.name!=y.name)

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)