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

SQLʹÓü¼ÇÉ

Ò»¡¢¼Ó¿ìsqlµÄÖ´ÐÐËÙ¶È
¡¡¡¡1.select Óï¾äÖÐʹÓÃsort,»òjoin
¡¡¡¡Èç¹ûÄãÓÐÅÅÐòºÍÁ¬½Ó²Ù×÷£¬Äã¿ÉÒÔÏÈselectÊý¾Ýµ½Ò»¸öÁÙʱ±íÖУ¬È»ºóÔÙ¶ÔÁÙʱ±í½øÐд¦Àí¡£ÒòΪÁÙʱ±íÊǽ¨Á¢ÔÚÄÚ´æÖУ¬ËùÒԱȽ¨Á¢ÔÚ´ÅÅÌÉϱí²Ù×÷Òª¿ìµÄ¶à¡£
¡¡¡¡È磺
SELECT time_records.*, case_name¡¡
from time_records, OUTER cases¡¡
WHERE time_records.client = "AA1000"¡¡
AND time_records.case_no = cases.case_no¡¡
ORDER BY time_records.case_no
¡¡¡¡Õâ¸öÓï¾ä·µ»Ø34¸ö¾­¹ýÅÅÐòµÄ¼Ç¼£¬»¨·ÑÁË5·ÖÖÓ42Ãë¡£¶ø£º
SELECT time_records.*, case_name¡¡
from time_records, OUTER cases¡¡
WHERE time_records.client = "AA1000"¡¡
AND time_records.case_no = cases.case_no¡¡
INTO temp foo;¡¡
SELECT * from foo ORDER BY case_no¡¡
·µ»Ø34Ìõ¼Ç¼£¬Ö»»¨·ÑÁË59Ãë¡£
¡¡¡¡2.ʹÓÃnot in »òÕßnot exists Óï¾ä
¡¡¡¡ÏÂÃæµÄÓï¾ä¿´ÉÏȥûÓÐÈκÎÎÊÌ⣬µ«ÊÇ¿ÉÄÜÖ´Ðеķdz£Âý£º
SELECT code from table1¡¡
WHERE code NOT IN ( SELECT code from table2
Èç¹ûʹÓÃÏÂÃæµÄ·½·¨£º
SELECT code, 0 flag¡¡
from table1¡¡
INTO TEMP tflag;¡¡
È»ºó£º
UPDATE tflag SET flag = 1
WHERE code IN ( SELECT code¡¡from table2¡¡
WHERE tflag.code = table2.code ;
È»ºó£º
SELECT * from¡¡
tflag¡¡
WHERE flag = 0;
¡¡¡¡¿´ÉÏÈ¥Ò²ÐíÒª»¨·Ñ¸ü³¤µÄʱ¼ä£¬µ«ÊÇÄã»á·¢ÏÖ²»ÊÇÕâÑù¡£
¡¡¡¡ÊÂʵÉÏÕâÖÖ·½Ê½Ð§Âʸü¿ì¡£ÓпÉÄܵÚÒ»ÖÖ·½·¨Ò²»áºÜ¿ì£¬ÄÇÊÇÔÚ¶ÔÏà¹ØµÄÿ¸ö×ֶζ¼½¨Á¢ÁËË÷ÒýµÄÇé¿öÏ£¬µ«ÊÇÄÇÏÔÈ»²»ÊÇÒ»¸öºÃµÄ×¢Òâ¡£
¡¡¡¡3.±ÜÃâʹÓùý¶àµÄ“or"
¡¡¡¡Èç¹ûÓпÉÄܵĻ°£¬¾¡Á¿±ÜÃâ¹ý¶àµØʹÓÃor£º WHERE a = "B" OR a = "C"
¡¡¡¡Òª±È WHERE a IN ("B","C") Âý¡£ ÓÐʱÉõÖÁUNION»á±ÈORÒª¿ì¡£
¡¡¡¡4.ʹÓÃË÷Òý
¡¡¡¡ÔÚËùÓеÄjoinºÍorder by µÄ×Ö¶ÎÉϽ¨Á¢Ë÷Òý¡£ ÔÚwhereÖеĴó¶àÊý×ֶν¨Á¢Ë÷Òý¡£
WHERE datecol >= "this/date" AND datecol
<= "that/date"¡¡Òª±È¡¡WHERE datecol BETWEEN
"this/date" AND "that/date" Âý¡£¡¡¡¡
¡¡¡¡5.ÔÚ·¢Éú´íÎóµÄʱºòÖÕÖ¹sql½Å±¾µÄÖ´ÐÐ
¡¡¡¡Èç¹ûÄã´´½¨ÁËÒ»¸ösql½Å±¾£¬²¢ÇÒÔÚUNIXÃüÁîÐÐÖÐʹÓÃÒÔϵķ½Ê½À´Ö´ÐÐÕâ¸ö½Å±¾£º
¡¡¡¡$ dbaccess <½Å±¾ÎļþÃû>
¡¡¡¡Õâʱ£¬½Å±¾ÖеÄËùÓеÄsqlÓï¾ä¶¼»á±»Ö´ÐУ¬¼´Ê¹ÆäÖеÄÒ»¸ösqlÓï¾ä·¢ÉúÁË´íÎó¡£ÀýÈ磬Èç¹ûÄã½Å±¾ÖÐΪÈçϵÄÓï¾ä£º
BEGIN WORK;¡¡
INSERT INTO history¡¡
SELECT *¡¡


Ïà¹ØÎĵµ£º

SQLÖÐCASEʹÓÃ

 ½ñÌìÔÚÏîÄ¿ÖÐÓÐÒ»ÎÊÌ⣬ÔÚÍøÉϲéѯÁËcaseµÄÓ÷¨£¬Ìû³öÀ´ºÍ´ó¼Ò·ÖÏíÏ¡£
 ÎÊÌâÃèÊö£ºÔÚÒ»ÕűíÖÐÓÐÒ»×Ö¶ÎbitÀàÐÍ£¬±íʾ´ËÌõÊý¾ÝÊÇ·ñ±»Ëø¶¨£¬ÔÚÒ³ÃæÉÏÓÐÒ»°´Å¥ÊǶԴËÌõÊý¾Ý½øÐÐËø¶¨ºÍ½âËøµÄ£¬Ñ¡ÔñÒ³ÃæÖеÄÊý¾Ý£¬µã»÷Õâ¸ö°´Å¥£¬Èç¹ûÕâÌõÊý¾ÝÊÇËø¶¨µÄ£¬¾Í½âËø£»Èç¹ûÊÇδ˵¶¨µÄ¾ÍËø¶¨£¬ÕâÑù¾ÍÓÃÒ»ÌõÓï¾äÀ´ÊµÏÖ¡£ºóÀ´Ï ......

DB2ÁÙʱ±íÔÚSQL¹ý³Ì

 
°æȨÉùÃ÷£ºÔ­´´×÷Æ·£¬ÈçÐèתÔØ£¬ÇëÓë×÷ÕßÁªÏµ¡£·ñÔò½«×·¾¿·¨ÂÉÔðÈΡ£
DB2ÁÙʱ±íÔÚSQL¹ý³ÌºÍSQLÓï¾äÖеIJâÊÔ×ܽá
 
²âÊÔÄ¿±ê£º
 
·Ö±ðÔÚSQL¹ý³ÌºÍSQLÓï¾äÖд´½¨ÁÙʱ±í£¬²¢²åÈëÊý¾Ý£¬¿´Ö´Ðнá¹ûÓÐʲôÒìͬ¡£
 
²âÊÔ»·¾³£º
 
DB2 UDB V9.1
 
Ö´Ðи½¼þÀïÃæµÄSQLÓï¾ä£¬µÃµ½Ò»¸ö±í¡ ......

sql server 2000 È«ÎÄË÷ÒýÈ«½â

 http://hi.baidu.com/dumao/blog/item/1cafa71e5886d019413417e4.html
1.È«ÎÄË÷Òý¸ÅÊö
¶Ô Microsoft® SQL Server™ 2000 Êý¾ÝµÄÈ«ÎÄÖ§³ÖÉæ¼°Á½¸ö¹¦ÄÜ£º¶Ô×Ö·ûÊý¾Ý·¢³ö²éѯµÄÄÜÁ¦ºÍ´´½¨¼°Î¬»¤»ù´¡Ë÷ÒýÒÔ¼ò»¯ÕâЩ²éѯµÄÄÜÁ¦¡£
È«ÎÄË÷ÒýÔÚÐí¶àµØ·½ÓëÆÕͨµÄ SQL Ë÷Òý²»Í¬¡£
ÆÕͨ SQL Ë÷ÒýÈ«ÎÄË÷Òý
´æ´¢Ê±ÊÜ ......

sql server ´æ´¢¹ý³Ì¼°´¥·¢Æ÷

Ò»Ö±¶¼ÏëÕÒ¸öʱ¼äÑо¿Ò»Ï£¬½ñÌ컨ÁËÒ»Ììʱ¼äȥʵ¼ùÁËһϣ¬·Ç³£ÓÐÓ᣿ÉÒÔ˵ÊÇÊý¾Ý¿âÀïÃæµÄ¾«»ª°É¡£»¹ºÃÎÒ½ñÌìȥŪÁ˼¸Ï£¬Ëä˵¶¼ÊÇЩ¼òµ¥µÄÓï¾ä£¬µ«ÊÇ×îÆðÂëÖªµÀÒÔºóÔÚÏîÄ¿¸ÃÔõôȥ×öÁË¡£ Ïл°ÉÙ˵¡£½øÈëÕýÌâ¡£
1.´´½¨SQL´æ´¢¹ý³Ì:
   CREATE PROCEDURE stu_proc1//Ö¸¶¨¹ý³ÌÃû
    @Sno varc ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ