sqlÖÐinµÄÓ÷¨
sql ÖÐ in ²Ù×÷·û¼ì²éÒ»¸öÖµÊÇ·ñ°üÀ¨ÔÚÒ»¸ö¸ø¶¨µÄÖµÁбíÖУºÓï·¨£ºcolumn_name in (value1, value2, …, valuen)µ± column_name ÖеÄÖµÓëÁбíÖÐÈκÎֵƥÅäʱ·µ»Ø true£¬²»È»·µ»Ø falseÓÅÊÆ£º¼ì²é¶à¸öֵʱ±ÈÆäËûÏàµÈ²Ù×÷·ûЧÂʸü¸ß
SQL ÖÐ IN Ó÷¨
IN ÊÇ SQL ÖÐÒ»¸öÓÃÓÚ¼ì²éÖµÊÇ·ñÔÚ¸ø¶¨ÁбíÖб£´æµÄÔËËã·û¡£ÆäÓï·¨ÈçÏ£º
column_name IN (value1, value2, ..., valueN)
µÇ¼ºó¸´ÖÆ
ÆäÖУº
column_name ÊÇÒª¼ì²éµÄÖµËùÔÚµÄÁС£
value1, value2, …, valueN ÊÇÒª¼ì²éµÄÖµÁÐ±í¡£
µ± column_name ÖеÄÖµÓëÁбíÖеÄÈκÎֵƥÅäʱ£¬IN ²Ù×÷·û·µ»Ø true£»²»È»·µ»Ø false¡£
Ó÷¨Ê¾Àý
ÒÔÏÂÊÇһЩ IN ²Ù×÷·ûµÄʹÓÃʾÀý£º
-- ¼ì²éÔ±¹¤±íÖÐ id Ϊ 1 µÄÔ±¹¤µÄÐÕÃû SELECT name FROM employees WHERE id IN (1); -- ¼ì²é²úÆ·±íÖмÛÇ®ÔÚ 100 µ½ 200 ÃÀÔªÖ®¼äµÄ²úÆ·µÄÃû³Æ SELECT name FROM products WHERE price IN (100, 200); -- ¼ì²é¶©µ¥±íÖаüÀ¨Ìض¨¿Í»§ ID µÄ¶©µ¥ºÅ SELECT order_id FROM orders WHERE customer_id IN (123, 456);
µÇ¼ºó¸´ÖÆ
×¢ÖØÊÂÏî
IN ²Ù×÷·û¿ÉÒÔ¼ì²é¶à¸öÖµ¡£
IN ²Ù×÷·ûÖеÄÖµ¿ÉÒÔÊdz£Á¿¡¢×ֶλò×ÓÅÌÎʵÄЧ¹û¡£
IN ²Ù×÷·ûͨ³£±ÈÆäËû¼ì²éÖµÏàµÈµÄ²Ù×÷·û£¨Èç = »ò £©Ð§Âʸü¸ß¡£
IN ²Ù×÷·û²»»á¶ÔÁбíÖеÄÖµ¾ÙÐÐÅÅÐò¡£
ÈôÊÇÁбíÖаüÀ¨¿ÕÖµ£¬IN ²Ù×÷·û½«·µ»Ø null¡£
ÒÔÉϾÍÊÇsqlÖÐinµÄÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡