mysql 中any,some,all,in的用法

IN

SELECT count(*) FROM world.country where Name IN (SELECT Name FROM world.country where Name like "C%"); 

匹配子集中的任一元素

NOT IN


SELECT count(*) FROM world.country where Name NOT IN (SELECT Name FROM world.country where Name like "C%"); 

匹配不属于某个子集的任一元素 
 

ALL

SELECT count(*) FROM world.country WHERE Name<>all(SELECT Name FROM world.country where Name like "C%");

与子集中的每一个元素
比如:
val>ALL(subset):表示val比subset中每一个元素都大
val<>ALL(subset):表示val不在subset中,等效于NOT IN (subset)

ANY,SOME

SELECT count(*) FROM world.country WHERE Name=any(SELECT Name FROM world.country where Name like "C%");

ANY表示任一个,SOME是ANY的变体,含义相同
比如:
val=ANY(subset):表示val等于subnet子集中的任何一个元素皆可,等同于val IN (subnet)
val>ANY(subnet):表示val比subnet中最小的元素大即可

你可能感兴趣的:(入门,mysql)