Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

sqlÖÐ in ¡¢not in ¡¢exists¡¢not exists Ó÷¨ºÍ²î±ð

exists £¨sql ·µ»Ø½á¹û¼¯ÎªÕ棩
not exists (sql ²»·µ»Ø½á¹û¼¯ÎªÕ棩
ÈçÏ£º
±íA
ID NAME
1    A1
2    A2
3  A3
±íB
ID AID NAME
1    1 B1
2    2 B2
3    2 B3
±íAºÍ±íBÊÇ£±¶Ô¶àµÄ¹Øϵ A.ID => B.AID
SELECT ID,NAME from A WHERE EXIST (SELECT * from B WHERE A.ID=B.AID)
Ö´Ðнá¹ûΪ
1 A1
2 A2
Ô­Òò¿ÉÒÔ°´ÕÕÈçÏ·ÖÎö
SELECT ID,NAME from A WHERE EXISTS (SELECT * from B WHERE B.AID=£±)
--->SELECT * from B WHERE B.AID=£±ÓÐÖµ·µ»ØÕæËùÒÔÓÐÊý¾Ý
SELECT ID,NAME from A WHERE EXISTS (SELECT * from B WHERE B.AID=2)
--->SELECT * from B WHERE B.AID=£²ÓÐÖµ·µ»ØÕæËùÒÔÓÐÊý¾Ý
SELECT ID,NAME from A WHERE EXISTS (SELECT * from B WHERE B.AID=3)
--->SELECT * from B WHERE B.AID=£³ÎÞÖµ·µ»ØÕæËùÒÔûÓÐÊý¾Ý
NOT EXISTS ¾ÍÊÇ·´¹ýÀ´
SELECT ID,NAME from A WHERE¡¡NOT EXIST (SELECT * from B WHERE A.ID=B.AID)
Ö´Ðнá¹ûΪ
3 A3
===========================================================================
EXISTS = IN,Òâ˼Ïàͬ²»¹ýÓï·¨ÉÏÓеãµãÇø±ð£¬ºÃÏñʹÓÃINЧÂÊÒª²îµã£¬Ó¦¸ÃÊDz»»áÖ´ÐÐË÷ÒýµÄÔ­Òò
SELECT ID,NAME from A¡¡ WHERE¡¡ID IN (SELECT AID from B)
NOT EXISTS = NOT IN ,Òâ˼Ïàͬ²»¹ýÓï·¨ÉÏÓеãµãÇø±ð
SELECT ID,NAME from A WHERE¡¡ID¡¡NOT IN (SELECT AID from B)
ÏÂÃæÊÇÆÕͨµÄÓ÷¨£º
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 ±íÖÐÑ¡Ôñ


Ïà¹ØÎĵµ£º

PL/SQL 001

ÔÚ Oracle 10g  ÖР
¿ÉÒÔͨ¹ý http://localhost:5560/isqlplus ·ÃÎÊ isqlplus 
ÔÚ isqlplus ÖÐ ¿ÉÒÔÖ´ÐÐ plsql
set serveroutput on size 100000   // ´ò¿ª ·þÎñÆ÷µÄÊä³ö  on ºóÃæÊÇ »º´æµÄ´óС ·¶Î§ÊÇ  (2000 ÖÁ 1000000)
begin
   dbms_output.put_line('hel ......

SQL ServerÊÂÎñÈÕÖ¾½ÒÃØ

ÊÂÎñÈÕÖ¾ÀïÃ擲ؔןܶàÓÐÓõÄÐÅÏ¢¡£ËäÈ»SQL Server±¾Éí²¢Ã»ÓÐÌṩ·ÖÎö¹¤¾ß£¬µ«ÊÇÎÒÃÇ¿ÉÒÔʹÓõÚÈý·½¹¤¾ßÀ´Ò»Ì½¾¿¾¹¡£
Red GateÈí¼þÌṩÁËÒ»¿î½Ð×öSQL Log RescueµÄÃâ·Ñ¹¤¾ß£¬µ«ÊÇÖ»Ö§³ÖSQL Server 2000¡£ApexSQLºÍLumigent¹«Ë¾ÌṩµÄÁ½¿îÈí¼þ·Ö±ð½Ð×öApexSQL LogºÍLog Explorer£¬ËüÃÇÖ§³ÖSQL Server7¡¢2000ºÍ ......

SQL 2008 ½Ø¶ÏÊÂÎñÈÕÖ¾²»ÄÜÓÃÁË£¿£¿

BACKUP DATABASENAME WITH NO_LOGÒ»Ö±ÊÇÎҽضÏÊÂÎñÈÕÖ¾£¬Ñ¹Ëõ¿Õ¼äµÄÀûÆ÷£¬½ñÌìÔÙSQL2008ÉÏÒ»Óã¬È´²»ÁéÁË
ÏûÏ¢ 3032£¬¼¶±ð 16£¬×´Ì¬ 2£¬µÚ 2 ÐÐ
´ËÓï¾ä²»Ö§³ÖÒ»¸ö»ò¶à¸öÑ¡Ïî(no_log)¡£Çë²éÔÄÎĵµÒÔÁ˽âËùÖ§³ÖµÄÑ¡Ïî¡£
²é¿´Áª»ú°ïÖúÊֲᣬÀïÃæȷʵûÓÐwith no_logµÄ¿ÉÑ¡ÏîÁË£¬ÄÇÔõô°ì°¡£¬50MµÄÊý¾ÝÎļþ£¬2GµÄÈÕÖ¾Îļþ£¬È ......

SQL ServerÖÐRollup¹Ø¼ü×ÖʹÓü¼ÇÉ

Ê×ÏÈ´´½¨²âÊÔ±í¡¢Ìí¼ÓÊý¾Ý¡£
create table #t(a int,b int,c int,d int,e int)
insert into #t values(1,2,3,4,5)
insert into #t values(1,2,3,4,6)
insert into #t values(1,2,3,4,7)
insert into #t values(1,2,3 ......

sql server 2005 Óû§È¨ÏÞ

ÒªÏë³É¹¦·ÃÎÊ SQL Server Êý¾Ý¿âÖеÄÊý¾Ý£¬ÎÒÃÇÐèÒªÁ½¸ö·½ÃæµÄÊÚȨ£ºÒ»¡¢»ñµÃ×¼ÐíÁ¬½Ó SQL Server ·þÎñÆ÷µÄȨÀû£»¶þ¡¢»ñµÃ·ÃÎÊÌض¨Êý¾Ý¿âÖÐÊý¾ÝµÄȨÀû£¨select, update, delete, create table ...£©¡£¼ÙÉ裬ÎÒÃÇ×¼±¸½¨Á¢Ò»¸ö dba Êý¾Ý¿âÕÊ»§£¬ÓÃÀ´¹ÜÀíÊý¾Ý¿â mydb¡£
1. Ê×ÏÈÔÚ SQL Server ·þÎñÆ÷¼¶±ð£¬´´½¨µÇ½ÕÊ»§£¨creat ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ