sqlÖÐinºÍ=µÄÇø±ð
sql ÖÐ in ºÍ = ÊÇÓÃÓÚ½ÏÁ¿ÖµµÄ²î±ðÔËËã·û¡£in ÓÃÓÚ¼ì²éÒ»¸öÖµÊÇ·ñÊôÓÚÒ»×éÌض¨Öµ£¬¶ø = ÓÃÓÚ½ÏÁ¿Á½¸öµ¥¶ÀµÄÖµ¡£
SQL ÖÐ IN ºÍ = µÄÇø±ð
Ö±½Ó»Ø¸²£º
IN ºÍ = ÊÇ SQL ÖÐÓÃÓÚ½ÏÁ¿ÖµµÄ²î±ðÔËËã·û¡£
ÏêϸڹÊÍ£º
1. Óï·¨
IN£º°ÑÒ»¸öÖµÓëһϵÁÐÖµ¾ÙÐнÏÁ¿£¬ÅжϸÃÖµÊÇ·ñÔÚ¸ÃϵÁÐÖС£Ó﷨Ϊ£º
SELECT * FROM table_name WHERE column_name IN (value1, value2, ..., valueN);
µÇ¼ºó¸´ÖÆ
=£º½ÏÁ¿Á½¸öµ¥¶ÀµÄÖµÊÇ·ñÏàµÈ¡£Ó﷨Ϊ£º
SELECT * FROM table_name WHERE column_name = value;
µÇ¼ºó¸´ÖÆ
2. Ó÷¨
IN£ºÓÃÓÚ¼ì²éÒ»¸öÖµÊÇ·ñÊôÓÚÒ»×éÌض¨Öµ¡£ÀýÈ磬²éÕÒËùÓÐÄêËêÔÚ 20 µ½ 30 ËêÖ®¼äµÄ¿Í»§£º
SELECT * FROM customers WHERE age IN (20, 21, 22, ..., 30);
µÇ¼ºó¸´ÖÆ
=£ºÓÃÓÚ½ÏÁ¿Á½¸öµ¥¶ÀµÄÖµ¡£ÀýÈ磬²éÕÒÓëÌض¨ ID Æ¥ÅäµÄ¿Í»§£º
SELECT * FROM customers WHERE customer_id = 12345;
µÇ¼ºó¸´ÖÆ
3. ÐÔÄÜ
¹ØÓÚСÐÍÊý¾Ý¼¯£¬IN ºÍ = µÄÐÔÄܲî±ð²»´ó¡£¿ÉÊÇ£¬¹ØÓÚ´óÐÍÊý¾Ý¼¯£¬IN µÄÐÔÄÜͨ³£ÓÅÓÚ =£¬ÓÉÓÚËü¿ÉÒÔÔÚµ¥¸öÅÌÎÊÖнÏÁ¿¶à¸öÖµ£¬¶ø = ÐèÒªÖ´Ðжà¸öÅÌÎÊ¡£
4. ¿É¶ÁÐÔ
¹ØÓÚ½ÏÁ¿ÉÙÁ¿µÄÖµ£¬= ÔËËã·ûÍùÍù¸ü¾ß¿É¶ÁÐÔ¡£¿ÉÊÇ£¬¹ØÓÚ½ÏÁ¿´ó×ڵĹæÄ£Öµ£¬IN ÔËËã·û¿ÉÄܸüÒ×ÓÚÔĶÁºÍÃ÷È·¡£
ÒÔÉϾÍÊÇsqlÖÐinºÍ=µÄÇø±ðµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡