sqlÖÐanyÊÇʲôÒâ˼
sqlÖеÄanyÒªº¦´ÊÓÃÓÚ¼ì²é×ÓÅÌÎÊÊÇ·ñ·µ»ØÈκÎÖª×ã¸ø¶¨Ìõ¼þµÄÐУºÓï·¨£ºany (subquery)Ó÷¨£ºÓë½ÏÁ¿ÔËËã·ûÒ»ÆðʹÓã¬ÈôÊÇ×ÓÅÌÎÊ·µ»ØÈκÎÖª×ãÌõ¼þµÄÐУ¬Ôòany±í´ïʽÆÀ¹ÀΪtrueÓŵ㣺¼ò»¯ÅÌÎÊ£¬Ìá¸ßЧÂÊ£¬ÊÊÓÃÓÚ´¦Öóͷ£´ó×ÚÊý¾Ý¾ÖÏÞÐÔ£º²»Ìṩ֪×ãÌõ¼þµÄÌض¨ÐУ¬ÈôÊÇ×ÓÅÌÎÊ·µ»Ø¶à¸öÖª×ãÌõ¼þµÄÐУ¬ÔòÖ»·µ»Øtrue
SQLÖеÄANY
ANYÔÚSQLÖÐÊÇÒ»¸öÒªº¦×Ö£¬ÓÃÓÚ¼ì²é×ÓÅÌÎÊ·µ»ØµÄÈκÎÒ»ÐÐÊÇ·ñÖª×ã¸ø¶¨Ìõ¼þ¡£ËüÓÃÓÚÈ·¶¨ÊÇ·ñ±£´æÖª×ãÌõ¼þµÄÐУ¬¶ø²»ÊÇ»ñÈ¡Öª×ãÌõ¼þµÄÌض¨ÐС£
Óï·¨£º
ANY (subquery)
µÇ¼ºó¸´ÖÆ
Ó÷¨£º
ANYͨ³£Óë½ÏÁ¿ÔËËã·û£¨Èç=¡¢>¡¢
ʾÀý£º
SELECT * FROM customers WHERE ANY (SELECT order_id FROM orders WHERE customer_id = customers.customer_id) > 100;
µÇ¼ºó¸´ÖÆ
¸ÃÅÌÎʽ«»ñÈ¡¿Í»§IDÓëÈκζ©µ¥ID´óÓÚ100µÄ¿Í»§¡£
Óŵ㣺
ANY¿ÉÒÔ¼ò»¯ÅÌÎÊ£¬×èֹʹÓÃǶÌ×ÅÌÎÊ¡£
Ëü¿ÉÒÔÌá¸ßÅÌÎÊЧÂÊ£¬ÓÉÓÚSQLÓÅ»¯Æ÷¿ÉÒÔÌø¹ý²»Öª×ãÌõ¼þµÄÐС£
Ëü¿ÉÒÔÓÃÓÚ´¦Öóͷ£°üÀ¨´ó×ÚÊý¾ÝµÄ±í¡£
¾ÖÏÞÐÔ£º
ANY²»Ìṩ֪×ãÌõ¼þµÄÌض¨ÐС£
ÈôÊÇ×ÓÅÌÎÊ·µ»Ø¶à¸öÖª×ãÌõ¼þµÄÐУ¬ÔòANY±í´ïʽֻ·µ»Øtrue¡£
ÆäËû×¢ÖØÊÂÏ
ANY¿ÉÒÔÓëALLÒªº¦×ÖÒ»ÆðʹÓã¬ÒÔ¼ì²éËùÓÐÐÐÊÇ·ñÖª×ãÌõ¼þ¡£
ANY¹ØÓÚ¼ì²éÊÇ·ñ±£´æÊý¾ÝºÜÊÇÓÐÓ㬶ø²»ÊǼìË÷Ìض¨Ãü¾Ý¡£
ÔÚijЩÇéÐÎÏ£¬Ê¹ÓÃEXISTSÒªº¦×Ö¿ÉÒÔ»ñµÃÀàËƵÄЧ¹û£¬µ«¿ÉÄÜЧÂʽϵ͡£
ÒÔÉϾÍÊÇsqlÖÐanyÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡