SQLÖÐIN,NOT IN,EXISTS,NOT EXISTSµÄÓ÷¨ºÍ²î±ð
SQLÖÐIN,NOT IN,EXISTS,NOT EXISTSµÄÓ÷¨ºÍ²î±ð:
IN:È·¶¨¸ø¶¨µÄÖµÊÇ·ñÓë×Ó²éѯ»òÁбíÖеÄÖµÏàÆ¥Åä¡£
IN ¹Ø¼ü×ÖʹÄúµÃÒÔÑ¡ÔñÓëÁбíÖеÄÈÎÒâÒ»¸öֵƥÅäµÄÐС£
µ±Òª»ñµÃ¾ÓסÔÚ California¡¢Indiana »ò Maryland ÖݵÄËùÓÐ×÷ÕßµÄÐÕÃûºÍÖݵÄÁбíʱ£¬¾ÍÐèÒªÏÂÁвéѯ£º
SELECT ProductID, ProductName from Northwind.dbo.Products WHERE CategoryID = 1 OR CategoryID = 4 OR CategoryID = 5
È»¶ø£¬Èç¹ûʹÓà IN£¬ÉÙ¼üÈëһЩ×Ö·ûÒ²¿ÉÒԵõ½Í¬ÑùµÄ½á¹û£º
SELECT ProductID, ProductName from Northwind.dbo.Products WHERE CategoryID IN (1, 4, 5)
IN ¹Ø¼ü×ÖÖ®ºóµÄÏîÄ¿±ØÐëÓöººÅ¸ô¿ª£¬²¢ÇÒÀ¨ÔÚÀ¨ºÅÖС£
ÏÂÁвéѯÔÚ titleauthor ±íÖвéÕÒÔÚÈÎÒ»ÖÖÊéÖеõ½µÄ°æË°ÉÙÓÚ 50% µÄËùÓÐ×÷ÕßµÄ au_id£¬È»ºó´Ó authors ±íÖÐÑ¡Ôñ au_id Óë
titleauthor ²éѯ½á¹ûÆ¥ÅäµÄËùÓÐ×÷ÕßµÄÐÕÃû£º
SELECT au_lname, au_fname from authors WHERE au_id IN (SELECT au_id from titleauthor WHERE royaltyper < 50)
½á¹ûÏÔʾÓÐһЩ×÷ÕßÊôÓÚÉÙÓÚ 50% µÄÒ»Àà¡£
NOT IN:ͨ¹ý NOT IN ¹Ø¼ü×ÖÒýÈëµÄ×Ó²éѯҲ·µ»ØÒ»ÁÐÁãÖµ»ò¸ü¶àÖµ¡£
ÒÔϲéѯ²éÕÒûÓгö°æ¹ýÉÌÒµÊé¼®µÄ³ö°æÉ̵ÄÃû³Æ¡£
SELECT pub_name from publishers WHERE pub_id NOT IN (SELECT pub_id from titles WHERE type = 'business')
ʹÓà EXISTS ºÍ NOT EXISTS ÒýÈëµÄ×Ó²éѯ¿ÉÓÃÓÚÁ½ÖÖ¼¯ºÏÔÀíµÄ²Ù×÷£º½»¼¯Óë²î¼¯¡£Á½¸ö¼¯ºÏµÄ½»¼¯°üº¬Í¬Ê±ÊôÓÚÁ½¸öÔ¼¯ºÏµÄËùÓÐÔªËØ¡£
²î¼¯°üº¬Ö»ÊôÓÚÁ½¸ö¼¯ºÏÖеĵÚÒ»¸ö¼¯ºÏµÄÔªËØ¡£
EXISTS:Ö¸¶¨Ò»¸ö×Ó²éѯ£¬¼ì²âÐеĴæÔÚ¡£
±¾Ê¾ÀýËùʾ²éѯ²éÕÒÓÉλÓÚÒÔ×Öĸ B ¿ªÍ·µÄ³ÇÊÐÖеÄÈÎÒ»³ö°æÉ̳ö°æµÄÊéÃû£º
SELECT DISTINCT pub_name from publishers WHERE EXISTS (SELECT * from titles WHERE pub_id = publishers.pub_id AND type =
'business')
SELECT distinct pub_name from publishers WHERE pub_id IN (SELECT pub_id from titles WHERE type = 'business')
Á½ÕßµÄÇø±ð:
EXISTS:ºóÃæ¿ÉÒÔÊÇÕû¾äµÄ²éѯÓï¾äÈç:SELECT * from titles
IN:ºóÃæÖ»ÄÜÊǶԵ¥ÁÐ:SELECT pub_id from titles
NOT EXISTS:
ÀýÈ磬Ҫ²éÕÒ²»³ö°æÉÌÒµÊé¼®µÄ³ö°æÉ̵ÄÃû³Æ£º
SELECT pub_name from publishers WHERE NOT EXISTS (SELECT * from titles WHERE pub_id = publishers.pub_id AND type =
'business')
ÏÂÃæµÄ²éѯ²éÕÒÒѾ²»ÏúÊÛµÄÊéµÄÃû³Æ:
SELECT title from titles WHERE NOT EXI
Ïà¹ØÎĵµ£º
ÔÚ´óÐ͵ÄÊý¾Ý¿âÓ¦ÓÃÖУ¬¾³£»áÓöµ½²¿·ÖÊý¾ÝµÄÍÑ»úºÍ¶à¸öÊý¾Ý¿âµÄºÏ²¢ÎÊÌâ¡£±ÈÈçÏÖÔÚÓÐÒ»¸öÈ«Ê¡·¶Î§Ê¹ÓõÄÓ¦ÓóÌÐò£¬Ã¿¸öÊж¼²¿ÊðÁ˵¥¶ÀµÄÏàͬµÄÓ¦ÓóÌÐò·þÎñÆ÷ºÍÊý¾Ý¿â·þÎñÆ÷£¬Ã¿¸öÔÂÐèÒª½«È«Ê¡ËùÓÐÊеÄÊý¾ÝÈ«²¿»ã×ÜÆðÀ´ÓÃÓÚ³öÈ«Ê¡µÄ±¨±í£¬ÕâÊÇÒ»Öֺܳ£¼ûµÄÊý¾Ý¿âºÏ²¢ÎÊÌâ¡£ÔÙ±ÈÈçÎÒÃÇ×öÁËÒ»¸öSmartClientµÄÓ¦ÓóÌÐò£¬Ã¿¸ö¿ ......
c06 --------------7545623Ìõ
c05---------------1032652Ìõ
vc01--------------427741Ìõ
SQL Statement from editor:
select c0602 "ÉÌÆ·±àÂë",c0625 "ÉÌÆ·ÌõÂë",
c0103 "ÉÌÆ·Ãû³Æ",c0104 "¹æ¸ñ",c060 ......
http://www.javaeye.com/topic/366991#
×÷Ϊһ¸ö¿ª·¢ÈËÔ±£¬¿ªÊ¼ÈÏÕæϵͳѧϰ
Oracle SQLÒ²Ö»ÓÐÔÂÓ֮࣬ǰµÄ
SQLÖª
ʶ½ö½öÊÇÏîÄ¿ÀïÃæÓõ½Ê²Ã´¾ÍÈ¥¿´Ê²Ã´£¬¼òµ¥Ëµ¾ÍÊÇ
Read The Fxxking Guide¡£ÔÚϵͳѧϰ
Oracle
SQL֮ǰ£¬°³µÄÏë·¨¾ÍÊÇ“°´ÕÕÐèÇóÍê³É¹¦ÄÜ£¬Ê£ÏµĽ»¸ø
DBAÀ´´¦À픡£Õâ¸öÏë·¨´ÓÕûÌåÀ´¿´ÏÔ ......
SQLÖÐDATEADDºÍDATEDIFFµÄÓ÷¨
ÈÕÆÚ:2008-07-17 ×÷Õß:ϲ騰С¶þ 來Ô´:PHPChina
ͨ³££¬妳ÐèÒª獲µÃ當Ç°ÈÕÆÚºÍ計ËãһЩÆäËûµÄÈÕÆÚ£¬ÀýÈ磬妳µÄ³ÌÐò¿ÉÄÜÐèÒªÅÐ斷Ò»個ÔµĵÚÒ»Ìì»òÕß×îááÒ»Ìì¡£妳們´ó²¿·ÖÈË´ó¸Å¶¼ÖªµÀÔõ樣°ÑÈÕÆÚ進ÐзָÄê ......
×î½ü¼¸ÖÜÒ»Ö±ÔÚ½øÐÐÊý¾Ý¿âÅàѵ£¬ÀÏʦ¾«Õ¿µÄ¼¼ÊõºÍÉú¶¯µÄ½²½âʹÎÒÊÜÒæ·Ëdz¡£ÎªÁËÈøü¶àµÄÐÂÊÖÊÜÒ棬ÎÒ³é¿Õ°ÑSQLÓï¾äÓÅ»¯²¿·Ö½øÐÐÁËÕûÀí£¬Ï£Íû´ó¼ÒÒ»Æð½ø²½¡£¡¡¡¡
¡¡¡¡Ò»¡¢²Ù×÷·ûÓÅ»¯¡¡¡¡
¡¡1¡¢IN ²Ù×÷·û ¡¡¡¡
¡¡¡¡ÓÃINд³öÀ´µÄSQLµÄÓŵãÊDZȽÏÈÝÒ×д¼°ÇåÎúÒ׶®£¬Õâ±È½ÏÊʺÏÏÖ´úÈí¼þ¿ª·¢µÄ·ç¸ñ¡£µ«ÊÇÓÃINµÄSQLÐÔÄÜ×ÜÊÇ±È½Ï ......