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

SQL»ù´¡½Ì³Ì

SQL ½Ì³Ì
1£©SQL ¼ò½é
SQL(Structured Query Language£¬½á¹¹²éѯÓïÑÔ)ÊÇÒ»¸ö¹¦ÄÜÇ¿´óµÄÊý¾Ý¿âÓïÑÔ¡£SQLͨ³£Ê¹ÓÃÓÚÊý¾Ý¿âµÄͨѶ¡£ANSI£¨ÃÀ¹ú¹ú¼Ò±ê׼ѧ»á£©Éù³Æ£¬SQLÊǹØϵÊý¾Ý¿â¹ÜÀíϵͳµÄ±ê×¼ÓïÑÔ¡£SQLÓï¾äͨ³£ÓÃÓÚÍê³ÉһЩÊý¾Ý¿âµÄ²Ù×÷ÈÎÎñ£¬±ÈÈçÔÚÊý¾Ý¿âÖиüÐÂÊý¾Ý£¬»òÕß´ÓÊý¾Ý¿âÖмìË÷Êý¾Ý¡£Ê¹ÓÃSQLµÄ³£¼û¹ØϵÊý¾Ý¿â¹ÜÀíϵͳÓУºOracle¡¢ Sybase¡¢ Microsoft SQL Server¡¢ Access¡¢ IngresµÈµÈ¡£ËäÈ»¾ø´ó¶àÊýµÄÊý¾Ý¿âϵͳʹÓÃSQL£¬µ«ÊÇËüÃÇͬÑùÓÐËüÃÇ×ÔÁ¢ÁíÍâµÄרÓÐÀ©Õ¹¹¦ÄÜÓÃÓÚËüÃǵÄϵͳ¡£µ«ÊÇ£¬±ê×¼µÄSQLÃüÁ±ÈÈç"Select"¡¢ "Insert"¡¢ "Update"¡¢ "Delete"¡¢ "Create"ºÍ "Drop"³£³£±»ÓÃÓÚÍê³É¾ø´ó¶àÊýÊý¾Ý¿âµÄ²Ù×÷¡£
¡¡¡¡µ«ÊÇ£¬²»ÏñÆäËüµÄÓïÑÔ£¬ÈçC¡¢PascalµÈ£¬SQLûÓÐÑ­»·½á¹¹£¨±ÈÈçif-then-else¡¢do-while£©ÒÔ¼°º¯Êý¶¨ÒåµÈµÈµÄ¹¦ÄÜ¡£¶øÇÒSQLÖ»ÓÐÒ»¸öÊý¾ÝÀàÐ͵Ĺ̶¨ÉèÖ㬻»¾ä»°Ëµ£¬Äã²»ÄÜÔÚʹÓÃÆäËü±à³ÌÓïÑÔµÄʱºò´´½¨Äã×Ô¼ºµÄÊý¾ÝÀàÐÍ¡£
SQL¹¦ÄÜÇ¿´ó£¬µ«ÊǸÅÀ¨ÆðÀ´£¬Ëü¿ÉÒÔ·Ö³ÉÒÔϼ¸×飺
DML£¨Data Manipulation Language£¬Êý¾Ý²Ù×÷ÓïÑÔ£©£ºÓÃÓÚ¼ìË÷»òÕßÐÞ¸ÄÊý¾Ý£»
DDL£¨Data Definition Language£¬Êý¾Ý¶¨ÒåÓïÑÔ£©£º ÓÃÓÚ¶¨ÒåÊý¾ÝµÄ½á¹¹£¬±ÈÈç ´´½¨¡¢Ð޸ĻòÕßɾ³ýÊý¾Ý¿â¶ÔÏó£»
DCL£¨Data Control Language£¬Êý¾Ý¿ØÖÆÓïÑÔ£©£ºÓÃÓÚ¶¨ÒåÊý¾Ý¿âÓû§µÄȨÏÞ¡£
2£©SQL ³£ÓÃÓï¾ä
2£®1   SELECT Óï¾ä
×÷ÓãºSELECT Óï¾äÓÃÓÚ´Ó±íÖÐÑ¡È¡Êý¾Ý¡£½á¹û±»´æ´¢ÔÚÒ»¸ö½á¹û±íÖУ¨³ÆΪ½á¹û¼¯£©¡£
Óï·¨£º
SELECT Ä¿±ê±íµÄÒ»¸ö»ò¶à¸öÁÐÃû³Æ,ÁÐÃûÇ°¿É¼Ó±í´ïʽ,Èç:avg(ÄêÁä) from Ä¿±ê±íµÄÃû³Æ;
ÒÔ¼°£º
SELECT * from ±íÃû³Æ;
×¢ÊÍ£º*´ú±íÑ¡È¡È«²¿¡£
 
ʾÀý£º
ÏÂÃæÊÇʾ·¶ÔÚÒ»¸ö±íÖÐÑ¡È¡×Ô¼ºÏëÒªµÄÐÅÏ¢£¬ÀýÈçÎÒÖ»ÏëÒªÀÏʦÃǵÄÁªÏµµç»°¡£
ÕâÊÇÔ­±í£¨½Ìʦ±í£©£¬ÀïÃæ°üº¬Á˽Ìʦ±àºÅµÈµÈÐÅÏ¢£¬ÔÚÕâ¸ö±íÖй¤×÷ʱ¼ä¡¢ÕþÖÎÃæÄ¿µÈµÈ¶¼ÊÇÎÒÃDz»ÐèÒªÖªµÀµÄÐÅÏ¢ËùÒÔÎÒÃÇÒªÓÐÑ¡ÔñµÄÑ¡È¡¡£
Õâ¸öÊÇÔÚSQLÊÓͼÖÐÊäÈëµÄ´úÂ루ÈçºÎ´ò¿ªSQLÊÓͼ²»ÔÚÕâÀïÁо٣©¡£
´úÂëµÄº¬ÒåÊÇ£ºÑ¡È¡“½Ìʦ±àºÅ,ÐÕÃû,ÐÔ±ð,ÁªÏµµç»°“ÕâËĸöÁУ¬ÁеÄÀ´Ô´ÊÇ“½Ìʦ“Õâ¸ö±í
Õâ¸öÊÇ×îÖյĽá¹û£¬¿ÉÒÔ¿´µ½Ö»ÓÐÎÒÃÇÒªµÄ“½Ìʦ±àºÅ,ÐÕÃû,ÐÔ±ð,ÁªÏµµç»°“ÁУ¬ÕþÖÎÃæÄ¿µÈ²¢Ã»ÓÐÔÚÀïÃæ¡£
 
 
ÍØÕ¹1£º
SELECT DISTINCT Óï¾ä
×÷ÓãºÔÚÒ»¸ö±íÖУ¬¿ÉÄÜ»á°üº¬Öظ´Öµ¡£Õâ²¢²»³ÉÎÊÌ⣬²»¹ý£¬ÓÐʱÄãÒ²ÐíÏ£Íû½ö½öÁгö²»Í¬£¨distinct£©µ


Ïà¹ØÎĵµ£º

sqlǶÌ××Ó²éѯ

×Ó²éѯ£º
ʹÓÃ×Ó²éѯµÄÔ­Ôò
1.Ò»¸ö×Ó²éѯ±ØÐë·ÅÔÚÔ²À¨ºÅÖС£
2.½«×Ó²éѯ·ÅÔڱȽÏÌõ¼þµÄÓÒ±ßÒÔÔö¼Ó¿É¶ÁÐÔ¡£
×Ó²éѯ²»°üº¬ ORDER BY ×Ӿ䡣¶ÔÒ»¸ö SELECT Óï¾äÖ»ÄÜÓÃÒ»¸ö ORDER BY ×Ӿ䣬
²¢ÇÒÈç¹ûÖ¸¶¨ÁËËü¾Í±ØÐë·ÅÔÚÖ÷ SELECT Óï¾äµÄ×îºó¡£
ORDER BY ×Ó¾ä¿ÉÒÔʹÓ㬲¢ÇÒÔÚ½øÐÐ Top-N ·ÖÎöʱÊDZØÐëµÄ¡£
3.ÔÚ×Ó² ......

SQLÖеÄCASEʹÓ÷½·¨

Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseËÑË÷º¯Êý¡£
--¼òµ¥Caseº¯Êý
CASE sex
         WHEN '1' THEN 'ÄÐ'
         WHEN '2' THEN 'Å®'
ELSE 'ÆäËû' END
--CaseËÑË÷º¯Êý
CASE WHEN sex = '1' THEN 'ÄÐ'
     ......

SQL With cube

ÏÐÀ´Ð´ÏÂwith cubeµÄÓ÷¨
cubeÔËËã·ûÔÚ SELECT Óï¾äµÄ GROUP BY ×Ó¾äÖÐÖ¸¶¨¡£¸ÃÓï¾äµÄÑ¡ÔñÁбíÓ¦°üº¬Î¬¶ÈÁк;ۺϺ¯Êý±í´ïʽ¡£GROUP BY Ó¦Ö¸¶¨Î¬¶ÈÁк͹ؼü×Ö WITH CUBE¡£½á¹û¼¯½«°üº¬Î¬¶ÈÁÐÖи÷ÖµµÄËùÓпÉÄÜ×éºÏ£¬ÒÔ¼°ÓëÕâЩά¶ÈÖµ×éºÏÏàÆ¥ÅäµÄ»ù´¡ÐÐÖеľۺÏÖµ¡£
ÏÈ¿´ÏÂ±í£º
ÎÒÃÇÒÔid¾ÛºÏ²éѯ³öƽ¾ù·Ö
ÕâÒ»ÌõSQLÓï¾äÓ ......

²éѯÖظ´¼Ç¼µÄSQLÓï¾ä

SELECT tagid, tagname from uchome_mtag WHERE tagname IN (SELECT tagname from uchome_mtag GROUP BY tagname HAVING (COUNT(tagname) > 1)) ORDER BY tagname ......

SQL ServerÖÐË÷Òý

Ò»¡¢SQL ServerÖÐÊý¾ÝÐеĴ洢·½Ê½
     ÔÚSQL ServerÖдæ·ÅÊý¾ÝµÄÎļþ»áÒÔ8KBµÄ´óС·ÖÒ³¡£Ã¿Ò»Ò³¿ÉÒÔÊÇÊý¾Ý¡¢Ë÷ÒýÒÔ¼°ÆäËûSQL ServerÊý¾Ý¿âÐèҪΪÆäά»¤Êý¾ÝÎļþµÄÊý¾ÝÀàÐÍ¡£´ó¶àÊýÒ³ÊÇÊý¾ÝÒ³»òË÷ÒýÒ³¡£Ò³ÊÇSQL Server¶Á¡¢Ð´Êý¾ÝÎļþµÄµ¥Ôª¡£Ã¿Ò»Ò³Ö»°üÀ¨Ò»¸ö¶ÔÏóµÄÊý¾Ý»òË÷ÒýÐÅÏ¢£¬ËùÒÔÔÚÿһ¸öÊý¾Ý ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ