sqlÖеÄinÊÇʲôÒâ˼
sql ÖÐ in ²Ù×÷·ûÓÃÓÚ¼ì²éÖ¸¶¨ÖµÊÇ·ñÔÚ¸ø¶¨ÜöÝÍÖУ¬Í¨¹ý¼ì²éÖ¸¶¨ÁеÄÖµÊÇ·ñÓëÜöÝÍÖеÄֵƥÅäÀ´¹ýÂËÊý¾Ý£¬ÊÊÓÃÓÚ²éÕÒÓëÌض¨ÖµÆ¥ÅäµÄÖµ¡¢¼ì²éÖµÊÇ·ñÊôÓÚÒÑÖªÖÖ±ð¡¢ÓÅ»¯ÅÌÎÊÐÔÄÜ¡£Ê¾Àý£º²éÕÒ°üÀ¨ “john”¡¢”jane” »ò “mark” Ö®Ò»×÷ΪÃû³ÆµÄÔ±¹¤£»²éÕÒ²»°üÀ¨ “red” »ò “blue” Ö®Ò»×÷ΪÑÕÉ«µÄ²úÆ·¡£
SQL ÖÐ IN µÄ¼ÄÒå
ÔÚ SQL ÅÌÎÊÓïÑÔÖУ¬IN ²Ù×÷·ûÓÃÓÚ¼ì²é¸ø¶¨ÖµÊÇ·ñÔÚÖ¸¶¨ÜöÝÍÖС£ËüµÄÓï·¨ÈçÏ£º
SELECT ... FROM table_name WHERE column_name IN (value1, value2, ...)
µÇ¼ºó¸´ÖÆ
×÷ÓÃ
IN ²Ù×÷·ûͨ¹ý¼ì²éÖ¸¶¨ÁеÄÖµÊÇ·ñÓëÒ»×é¸ø¶¨µÄֵƥÅäÀ´¹ýÂËÊý¾Ý¡£Ëü·µ»ØÓë¸ø¶¨ÜöÝÍÖеÄÖÁÉÙÒ»¸öֵƥÅäµÄËùÓÐÐС£
ÓÅÊÆ
IN ²Ù×÷·ûÓë NOT IN ²Ù×÷·ûÒ»ÆðʹÓÃʱ£¬ºÜÊÇÊʺÏÖ´ÐУº
²éÕÒÓëÌض¨ÖµÁбíÆ¥ÅäµÄÖµ
¼ì²éÖµÊÇ·ñÊôÓÚÒ»×éÒÑÖªµÄÖÖ±ð
ÓÅ»¯ÅÌÎÊÐÔÄÜ£¬ÓÉÓÚËüÃÇʹÓÃË÷ÒýÀ´¿ìËÙ²éÕÒÊý¾Ý
ʾÀý
ÒÔÏÂÅÌÎÊÕÒµ½°üÀ¨ “John”¡¢”Jane” »ò “Mark” Ö®Ò»×÷ΪÃû³ÆµÄÔ±¹¤£º
SELECT * FROM employees WHERE name IN ('John', 'Jane', 'Mark')
µÇ¼ºó¸´ÖÆ
ÒÔÏÂÅÌÎÊÕÒµ½²»°üÀ¨ “Red” »ò “Blue” Ö®Ò»×÷ΪÑÕÉ«µÄ²úÆ·£º
SELECT * FROM products WHERE color NOT IN ('Red', 'Blue')
µÇ¼ºó¸´ÖÆ
×¢ÖØ
IN ²Ù×÷·ûÖ»ÄÜÓëÁÐ±í£¨ÖµÜöÝÍ£©Ò»ÆðʹÓá£
IN ²Ù×÷·ûÖпÉÒÔ°üÀ¨×ÓÅÌÎÊ¡£
IN ²Ù×÷·û¿ÉÒÔÓëÆäËû²Ù×÷·û£¨Èç AND¡¢OR£©ÍŽáʹÓá£
ÒÔÉϾÍÊÇsqlÖеÄinÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡