sqlÖÐallºÍanyÇø±ð
sql ÖÐµÄ all ºÍ any ½ÏÁ¿×ÓÅÌÎÊЧ¹ûÓëÖ÷ÅÌÎÊЧ¹û¡£all ÒªÇó×ÓÅÌÎʶÔÿһÐзµ»ØÕæÖµ£¬¶ø any Ö»ÐèÒª¶ÔÖÁÉÙÒ»Ðзµ»ØÕæÖµ¡£Òò´Ë£¬all ½ÏÁ¿¸üÑϿᣬͨ³£ÓÃÓÚÈ·¶¨ÊÇ·ñÖª×ãËùÓÐÌõ¼þ£¬¶ø any ½ÏÁ¿¸ü¿íËÉ£¬ÓÃÓÚÈ·¶¨ÊÇ·ñ±£´æÖÁÉÙÒ»¸öÌõ¼þÖª×ã¡£
SQL ÖÐ ALL ºÍ ANY µÄÇø±ð
Ö±ÑÔ²»»ä»Ø¸²£º
SQL ÖÐµÄ ALL ºÍ ANY ÊÇÁ½¸ö²î±ðµÄÒªº¦×Ö£¬ÓÃÓÚ½ÏÁ¿×ÓÅÌÎʵÄЧ¹ûÓëÖ÷ÅÌÎʵÄЧ¹û¡£
Ïêϸ»Ø¸²£º
1. ALL
ALL ÔËËã·û¼ì²é×ÓÅÌÎÊÊÇ·ñ¶ÔÖ÷ÅÌÎʵÄÿһÐж¼·µ»ØÕæÖµ¡£ÈôÊÇ×ÓÅÌÎʶÔËùÓÐÐж¼·µ»ØÕæÖµ£¬Ôò ALL ½ÏÁ¿·µ»ØÕæÖµ£»²»È»·µ»Ø¼ÙÖµ¡£
ʾÀý£º
SELECT * FROM customer WHERE ALL (SELECT 1 FROM purchase WHERE customer_id = customer.id);
µÇ¼ºó¸´ÖÆ
¸ÃÅÌÎÊ·µ»ØËùÓпͻ§£¬ÆäÖÐÿһ¸ö¶¼ÖÁÉÙ¾ÙÐÐÁËÒ»´Î¹ºÖá£
2. ANY
ANY ÔËËã·û¼ì²é×ÓÅÌÎÊÊÇ·ñ¶ÔÖ÷ÅÌÎʵÄÈκÎÒ»Ðзµ»ØÕæÖµ¡£ÈôÊÇ×ÓÅÌÎʶÔÖÁÉÙÒ»Ðзµ»ØÕæÖµ£¬Ôò ANY ½ÏÁ¿·µ»ØÕæÖµ£»²»È»·µ»Ø¼ÙÖµ¡£
ʾÀý£º
SELECT * FROM customer WHERE ANY (SELECT 1 FROM purchase WHERE customer_id = customer.id);
µÇ¼ºó¸´ÖÆ
¸ÃÅÌÎÊ·µ»ØËùÓпͻ§£¬ÆäÖÐÖÁÉÙÓÐÒ»¸ö¾ÙÐÐÁ˹ºÖá£
×ܽ᣺
ÔËËã·û | ÐÎò |
---|---|
ALL | ×ÓÅÌÎʱØÐè¶ÔËùÓÐÐзµ»ØÕæÖµ |
ANY | ×ÓÅÌÎʱØÐè¶ÔÖÁÉÙÒ»Ðзµ»ØÕæÖµ |
ÒÔÉϾÍÊÇsqlÖÐallºÍanyÇø±ðµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡