SQL INµÄÓ÷¨
ÔÚ SQL ÖУ¬ÔÚÁ½¸öÇé¿öÏ»áÓõ½ IN Õâ¸öÖ¸ÁÕâÒ»Ò³½«½éÉÜÆäÖÐÖ®Ò»©¥©¥Óë WHERE ÓйصÄÄÇÒ»¸öÇé¿ö¡£ÔÚÕâ¸öÓ÷¨Ï£¬ ÎÒÃÇÊÂÏÈÒÑÖªµÀÖÁÉÙÒ»¸öÎÒÃÇÐèÒªµÄÖµ£¬¶øÎÒÃǽ«ÕâЩ֪µÀµÄÖµ¶¼·ÅÈë IN Õâ¸ö×Ӿ䡣 IN Ö¸ÁîµÄÓ﷨ΪÏ£º
SELECT "À¸Î»Ãû"
from "±í¸ñÃû"
WHERE "À¸Î»Ãû" IN ('ÖµÒ»', 'Öµ¶þ', ...)
ÔÚÀ¨»¡ÄÚ¿ÉÒÔÓÐÒ»»ò¶à¸öÖµ£¬¶ø²»Í¬ÖµÖ®¼äÓɶºµã·Ö¿ª¡£Öµ¿ÉÒÔÊÇÊýÄ¿»òÊÇÎÄ×Ö¡£ ÈôÔÚÀ¨»¡ÄÚÖ»ÓÐÒ»¸öÖµ£¬ÄÇÕâ¸ö×Ó¾ä¾ÍµÈÓÚ
WHERE "À¸Î»Ãû" = 'ÖµÒ»'
¾ÙÀýÀ´Ëµ£¬ÈôÎÒÃÇÒªÔÚ Store_Information ±í¸ñÖÐÕÒ³öËùÓк¬¸Ç Los Angeles »ò San Diego µÄ×ÊÁÏ£¬
Store_Information ±í¸ñ
store_name
Sales
Date
Los Angeles
$1500
Jan-05-1999
San Diego
$250
Jan-07-1999
San Francisco
$300
Jan-08-1999
Boston
$700
Jan-08-1999
ÎÒÃǾʹòÈ룬
SELECT *
from Store_Information
WHERE store_name IN ('Los Angeles', 'San Diego')
½á¹û:
store_name
Sales
Date
Los Angeles
$1500
Jan-05-1999
San Diego
$250
Jan-07-1999
Ïà¹ØÎĵµ£º
ʹÓÃË÷Òý¿É¿ìËÙ·ÃÎÊÊý¾Ý¿â±íÖеÄÌض¨ÐÅÏ¢¡£Ë÷ÒýÊǶÔÊý¾Ý¿â±íÖÐÒ»Áлò¶àÁеÄÖµ½øÐÐÅÅÐòµÄÒ»Öֽṹ£¬ÀýÈç employee ±íµÄÐÕ£¨lname£©ÁС£Èç¹ûÒª°´ÐÕ²éÕÒÌض¨Ö°Ô±£¬Óë±ØÐëËÑË÷±íÖеÄËùÓÐÐÐÏà±È£¬Ë÷Òý»á°ïÖúÄú¸ü¿ìµØ»ñµÃ¸ÃÐÅÏ¢¡£
¡¡¡¡Ë÷ÒýÊÇÒ»¸öµ¥¶ÀµÄ¡¢ÎïÀíµÄÊý¾Ý¿â½á¹¹£¬ËüÊÇij¸ö±íÖÐÒ»ÁлòÈô¸ÉÁÐÖµµÄ¼¯ºÏºÍÏàÓ¦µÄÖ¸Ïò±íÖÐÎïÀ ......
×î½ü·ÖÇøMS SQL SERVERµÄ±í·ÖÇø£¬¸Ð¾õÉõÊǸ´ÔÓ¡£ 1. Ä¿Ç°Ö»ÖªµÀMS SQL SERVERÖ§³Ö·¶Î§·ÖÇøhttp://msdn.microsoft.com/zh-cn/library/ms187802.aspx£¬ ÔÚ¹Ù·½ÍøÕ¾µÄ˵Ã÷ÎĵµÀïÃ棬ҲûÓÐ˵֧³ÖÆäËûµÄ·ÖÇø¡£ÍøÉÏÓÐÐÖµÜ˵»¹Ö§³Öhash·ÖÇø¡£²»ÖªµÀÊÇÔõôʵÏֵġ£ÒòΪʹÓ÷ÖÇøº¯Êý£¬ÎÒÖ»ÖªµÀÄÜŪ³ö·¶Î§·ÖÇø¡£Í¬OracleµÄ±í·ÖÇøÏà± ......
¼ÙÉèÈçÏÂÓ¦Óãº
Á½Õű헗Óû§±íTDefUser£¨userid£¬address,phone£©ºÍÏû·Ñ±íTAccConsume(userid,time,amount)£¬ÐèÒª²éÏû·Ñ³¬¹ý5000µÄÓû§¼Ç¼¡£
ÓÃexists:
select * from TDefUser
where exists (select 1 from TAccConsume where TDefUser.userid=TAccConsume.userid and TAccConsume.amount>5000)
ÓÃi ......
SQLÓï¾äÓÅ»¯¼¼Êõ·ÖÎö
×î½ü¼¸ÖÜÒ»Ö±ÔÚ½øÐÐÊý¾Ý¿âÅàѵ£¬ÀÏʦ¾«Õ¿µÄ¼¼ÊõºÍÉú¶¯µÄ½²½âʹÎÒÊÜÒæ·Ëdz¡£ÎªÁËÈøü¶àµÄÐÂÊÖÊÜÒ棬ÎÒ³é¿Õ°ÑSQLÓï¾äÓÅ»¯²¿·Ö½øÐÐÁËÕûÀí£¬Ï£Íû´ó¼ÒÒ»Æð½ø²½¡£
Ò»¡¢²Ù×÷·ûÓÅ»¯
1¡¢IN ²Ù×÷·û
ÓÃINд³öÀ´µÄSQLµÄÓŵãÊDZȽÏÈÝÒ×д¼°ÇåÎúÒ׶®£¬Õâ±È½ÏÊʺÏÏÖ´úÈí¼þ¿ª·¢µÄ·ç¸ñ¡£µ«ÊÇÓÃINµÄSQLÐÔÄÜ×ÜÊÇ±È½Ï ......
ÔÚÉÏÒ»Ò³ÖУ¬ÎÒÃÇ¿´µ½ WHERE Ö¸Áî¿ÉÒÔ±»ÓÃÀ´Óɱí¸ñÖÐ ÓÐÌõ¼þµØÑ¡È¡×ÊÁÏ¡£ Õâ¸öÌõ¼þ¿ÉÄÜÊǼòµ¥µÄ (ÏñÉÏÒ»Ò³µÄÀý×Ó)£¬Ò²¿ÉÄÜÊǸ´Ôӵġ£¸´ÔÓÌõ¼þÊÇÓɶþ»ò¶à¸ö¼òµ¥Ìõ¼þ͸¹ý AND »òÊÇ OR µÄÁ¬½Ó¶ø³É¡£Ò»¸ö SQL Óï¾äÖпÉÒÔÓÐÎÞÏÞ¶à¸ö¼òµ¥Ìõ¼þµÄ´æÔÚ¡£
¸´ÔÓÌõ¼þµÄÓï·¨ÈçÏ£º
SELECT "À¸Î»Ãû"
from "±í¸ñÃû"
WHERE "¼òµ¥Ìõ¼ ......