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

¹¦ÄÜÇ¿´óµÄSQLÓï¾ä

1. ¸´ÖƱí½á¹¹
Sql´úÂë
   1. select * into B from A where 1=0;   
select * into B from A where 1=0;
 2.¸´ÖƱí¼Ç¼ ¸´ÖÆÄ³Ð©×Ö¶Î
Sql´úÂë
   1. insert into B(a, b, c) select d, e, f from A;   
insert into B(a, b, c) select d, e, f from A;
  ¸´ÖÆÕû¸ö±í¼Ç¼
Sql´úÂë
   1. insert into B select * from A;   
insert into B select * from A;
3.ÍâÁ¬½Ó²éѯ
Sql´úÂë
   1. select A.a, A.b, A.c, B.c, B.d, B.f from A LEFT OUT JOIN B ON A.a = B.c; ¡¡  
select A.a, A.b, A.c, B.c, B.d, B.f from A LEFT OUT JOIN B ON A.a = B.c; ¡¡
4.È¡ÌØ¶¨Ê±¼äÄÚµÄÊý¾Ý
Sql´úÂë
   1. select * from A where datediff("minute", ¿ªÊ¼Ê±¼ä×Ö¶Î, getdate())>ʱ¼ä²î ¡¡  
select * from A where datediff("minute", ¿ªÊ¼Ê±¼ä×Ö¶Î, getdate())>ʱ¼ä²î ¡¡
5.Á½ÕŹØÁª±í£¬É¾³ýÖ÷±íÖÐÒѾ­ÔÚ¸±±íÖÐûÓеÄÐÅÏ¢
Sql´úÂë
   1. delete from A where not exists(select ID from B where A.infid=B.infid );  
delete from A where not exists(select ID from B where A.infid=B.infid );
6. ¸´ÔӵĶ༶Ìõ¼þ²éѯ
Sql´úÂë
   1. SELECT A.NUM, A.NAME, B.UPD_DATE, B.PREV_UPD_DATE   
   2.      from TABLE1,(SELECT X.NUM, X.UPD_DATE, Y.UPD_DATE PREV_UPD_DATE   
   3.                   from (SELECT NUM, UPD_DATE, INBOUND_QTY, STOCK_ONHAND   
   4.                         from TABLE2   
   5.                         WHERE TO_CHAR(UPD_DATE,’’YYYY/MM’’) =   
   6.         &nb


Ïà¹ØÎĵµ£º

SQL²Ù×÷È«¼¯

ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓᣠ  
 
SQL·ÖÀࣺ   
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)   
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)   
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£ ......

¾«µäSQLÓï¾ä

·ÖÀàͳ¼Æ×ÜÊý²¢ÅÅÐò¶à±íÁªºÏ²éѯµÄÁ½ÖÖ·½·¨
Àý:
²éѯµØÇø±íÖи÷Ê¡ÏÂÃæ³ÇÊÐ×ÜÊý,²¢¶Ô²éѯ½á¹ûȡǰʮÃû
·¨Ò»:
select b.id,a.[name],b.counts from n_area a,(select top 10 parent_id as id,sum(parent_id) as counts from n_area where parent_id<>0 group by parent_id order by sum(parent_id) desc
) b where ......

ms sql server ´´½¨Óû§


SQL code
´´½¨½ÇÉ«£¬Óû§£¬È¨ÏÞ
/*--ʾÀý˵Ã÷
ʾÀýÔÚÊý¾Ý¿âpubsÖд´½¨Ò»¸öÓµÓбíjobsµÄËùÓÐȨÏÞ¡¢ÓµÓбítitlesµÄSELECTȨÏ޵ĽÇÉ«r_test
Ëæºó´´½¨ÁËÒ»¸öµÇ¼l_test£¬È»ºóÔÚÊý¾Ý¿âpubsÖÐΪµÇ¼l_test´´½¨ÁËÓû§ÕË»§u_test
ͬʱ½«Óû§ÕË»§u_testÌí¼Óµ½½ÇÉ«r_testÖУ¬Ê¹Æäͨ¹ýȨÏ޼̳лñÈ¡ÁËÓë½ÇÉ«r_t ......

SQLÓÅ»¯( ÒýÓà )



 
SQLÓÅ»¯²éѯ
ÊÕ²Ø



Êý¾Ý¿âµÄ²éѯÓÅ»¯¼¼Êõ
Êý¾Ý¿âϵͳÊǹÜÀíÐÅϢϵͳµÄºËÐÄ£¬»ùÓÚÊý¾Ý¿âµÄÁª»úÊÂÎñ´¦Àí£¨OLTP£©ÒÔ¼°Áª»ú·ÖÎö´¦Àí(OLAP)ÊÇÒøÐС¢ÆóÒµ¡¢Õþ¸®µÈ²¿ÃÅ×îÎªÖØÒªµÄ¼ÆËã»úÓ¦
ÓÃÖ®Ò»¡£´Ó´ó¶à ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ