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

SQLÖÐexistsºÍinµÄÇø±ð

¼ÙÉèÈçÏÂÓ¦Óãº
Á½Õű헗Óû§±í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)
ÓÃin:
select * from TDefUser
where userid in (select userid from TAccConsume where TAccConsume.amount>5000)
ͨ³£Çé¿öϲÉÓÃexistsÒª±ÈinЧÂʸߡ£
////
exists()ºóÃæµÄ×Ó²éѯ±»³Æ×öÏà¹Ø×Ó²éѯ ËûÊDz»·µ»ØÁбíµÄÖµµÄ.Ö»ÊÇ·µ»ØÒ»¸ötrue»òfalseµÄ½á¹û(ÕâÒ²ÊÇΪʲô×Ó²éѯÀïÊÇ"select 1"µÄÔ­Òò£¬»»³É"select 6"ÍêȫһÑù£¬µ±È»Ò²¿ÉÒÔselect×ֶΣ¬µ«ÊÇÃ÷ÏÔЧÂʵÍЩ)
ÆäÔËÐз½Ê½ÊÇÏÈÔËÐÐÖ÷²éѯһ´Î£¨ÏȵóöÖ÷²éѯµÄ½á¹û£© ÔÙ¸ù¾ÝÖ÷²éѯÖеÄÿһÐÐÈ¥×Ó²éѯÀïÈ¥²éѯÓëÆä¶ÔÓ¦µÄ½á¹û.Èç¹ûÊÇtrueÔòÊä³ö,·´Ö®Ôò²»Êä³ö.
in()ºóÃæµÄ×Ó²éѯ ÊÇ·µ»Ø½á¹û¼¯µÄ,»»¾ä»°ËµÖ´ÐдÎÐòºÍexists()²»Ò»Ñù.×Ó²éѯÏȲúÉú½á¹û¼¯,È»ºóÖ÷²éѯÔÙÈ¥½á¹û¼¯ÀïÈ¥ÕÒ·ûºÏÒªÇóµÄ×Ö¶ÎÁбíÈ¥.·ûºÏÒªÇóµÄÊä³ö,·´Ö®Ôò²»Êä³ö.
£¨µÚÒ»´Î²éѯÕÒ³ö>5000µÄ½á¹û£¬µÚ¶þ´Î²éѯÅжÏuseridÊÇ·ñÔÚ½á¹ûÖУ©
////
±ÈÈçÓû§±íTDefUser£¨userid£¬address,phone£©£¬Ïû·Ñ±íTAccConsume(userid,time,amount)Êý¾ÝÈçÏ£º
Ïû·Ñ±í¾Û¼¯Ë÷ÒýÊÇuserid,time
Êý¾Ý£¨×¢ÒâÒòΪÓоۼ¯Ë÷Òý,ʵ¼Ê´æ´¢Ò²Êǰ´ÒÔÏ´ÎÐòµÄ£©
1   2006-1-1  200
1   2006-1-2  300
1   2006-1-2  500
1   2006-1-3  2000
1   2006-1-3  2000
1   2006-1-4  400
1   2006-1-5  500
2   2006-1-1  200
2   2006-1-2  300
2   2006-1-2  500
2   2006-1-3  2000
2   2006-1-3  6000
2   2006-1-4  400
2   2006-1-5  8000
3   2006-1-1  7000
3   2006-1-2  30000
3   2006-1-2  50000
3   2006-1-3  20000
Óï¾ä£º
select * from TDefUser
where exists (select 1 from TAccConsume where TDefUser.userid=TAccConsume.userid and TAccConsume.amount>5000)
¶ÔÓÚuserid=1£¬ÐèÒªÕÒËùÓмǼ£¬²Å


Ïà¹ØÎĵµ£º

sql ÈÕÖ¾¹ÜÀí


Çå³ý SQL SERVER 2005 ÊÂÎñÈÕÖ¾
£±.ÓÒ¼üÔÚÇå³ýÈÕÖ¾µÄÊý¾Ý¿â£¬Èç“TestDB”£¬µã»÷[н¨²éѯ£¨Q£©]
£².ÊäÈëÒÔÏÂSQLÓï¾ä£¬ÆäÖГTestDB”ÊÇÊý¾Ý¿âÃû³Æ
DUMP TRANSACTION TestDB WITH NO_LOG
£³.Ö´ÐиÃSQL£¬³É¹¦ºó¼ÌÐøÒÔϲÙ×÷
£´.ÓÒ¼ü¸ÃÊý¾Ý¿â½Úµã£¬µã»÷[ÈÎÎñ£¨T£©] -> [ÊÕËõ£¨S£©] -> [Îļþ ......

Sql³£¼ûÃæÊÔÌâ ÊÜÓÃÁË

1.
ÓÃÒ»ÌõSQL
Óï¾ä ²éѯ³öÿÃſζ¼´óÓÚ80
·ÖµÄѧÉúÐÕÃû
name   kecheng   fenshu
ÕÅÈý    
ÓïÎÄ       81
ÕÅÈý    
Êýѧ       75
ÀîËÄ    
ÓïÎÄ &nbs ......

ʹÓÃOracle sql_trace ¹¤¾ß

ǰÑÔ£º
    sql_trace ÊÇÎÒÔÚ¹¤×÷Öо­³£ÒªÓõ½µÄµ÷ÓŹ¤¾ß£¬Ïà±È½Ïstatspack ÎÒ¸üÔ¸ÒâÓÃÕâ¸ö¹¤¾ß¡£
    ÒòΪÊý¾Ý¿âÂýÔ­ÒòµÄ85%ÒÔÉÏÊÇÓÉÓÚsqlÎÊÌâÔì³ÉµÄ£¬statspackûÓÐsqlµÄÖ´Ðмƻ®¡£ÏÔʾûÓÐËüÖ±¹Û£¬·½±ã£¬¶ÔÏëÒªÕë¶ÔÐÔ²»Ç¿£¬
    1£¬½éÉÜÊý¾Ý¿âµ÷ÓÅÐèÒª¾­³£»áÓõ½µÄ¹¤¾ß ......

sql server Óë oracle µÄÇø±ð

ÎÒÏÈÅ×שÒýÓñ:      
     
  1.     ¿ª·¢ÐÔ:     SQLSERVER²»ÄÜ,ORACLEÄÜ×°ÔÚUNIXÉÏ      
  2.     ·ÖÇø±í:     SQLSERVER²»Ä ......

PL/SQLÀý×Ó

ÒÔÏÂÊǾ­²âÑéÄÜÕýÈ·ÔËÐеÄ:
create    table t_emp_log212
(
who varchar2(10) not null,
action varchar2(10) not null,
actime date
);
create or replace trigger tri_emp_insert
before insert
on t_emp
begin
insert into t_emp_log(who,action,actime)values(user,'insert',sysdate);
end ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ