SQLÓï¾äµÄÓÅ»¯
SQLÓï¾ä¼¶±ðµÄÓÅ»¯ÊÇÎÒÃÇʵ¼Ê¹¤×÷ÖнӴ¥×î¶àµÄ£¬¼¸ºõËùÓеÄÊý¾Ý¿âÓ¦ÓÃ˵µ½µ×¶¼ÊÇSQLÓï¾äµÄ¾ßÌåÖ´ÐУ¬Òò´ËÈçºÎ¶ÔSQL½Å±¾±¾Éí½øÐÐÓÅ»¯£¬Ìá¸ßÖ´ÐÐЧÂʾÍÏÔµÃÓÈΪÖØÒª¡£ÒÔÏÂÊÇһЩͨÓõÄÉè¼ÆÔÔò¡£
(1)ʹÓÃselectÓï¾ä²éѯʱ£¬¾¡Á¿²»ÒªÊ¹ÓÃselect *¡¡Óï¾ä£¬¶øÊÇÓ¦¸ÃÖ¸Ã÷¾ßÌåÒª²éѯµÄ×ֶΣ¬ÌáÈ¡µÄ×Ö¶ÎÊýÁ¿Ô½ÉÙ£¬²éѯµÄËÙ¶ÈÔ½¿ì¡£
¡¡¡¡(2)ʹÓÃOrder by Óï¾äÅÅÐòʱ£¬×îºÃ°´ÕÕ¾Û´ØË÷ÒýµÄ×Ö¶ÎÅÅÐò£¬ÕâÑù»á´ó´óÌá¸ßÅÅÐòµÄËٶȡ£
(3)¾¡Á¿²»ÒªÊ¹ÓÃor¹Ø¼ü×Ö£¬»òÊÇ in(),·ñÔò»áÒýÆðÈ«±íɨÃ裬´ó´ó¼õµÍÊý¾ÝµÄ¼ìË÷Ëٶȡ£
±ÈÈçÊý¾ÝÁ¿½Ï´óʱ£¨¼¸Ê®Íò¼Ç¼£©£¬²»ÒªÊ¹ÓÃÈçϵÄSQLÓï¾ä£º
Select count(*) from student where id in('0','1')
Select count (*) from student where id='0' or id='1'
Ó¦¸Ã²ð·Ö³ÉÈçÏÂÁ½ÌõSQLÓï¾ä£º
select count(*) from student where id ='0'
select count (*)from student where id='1'
(4)¶ÔµÑ¿¨¶û»ý,Óα꣬ѻ·Òª½÷É÷ʹÓá£
(5)´æ´¢¹ý³Ì£¬º¯Êý£¬°ü£¬´¥·¢Æ÷µÈ¾¡Á¿²»Òª³¬¹ý1000ÐУ¬Ö®¼äµ÷Óò»Òª¸´ÔÓ¡£
(6)¼ì²éǶÌ×£¬µÝ¹é£¬×Ó²éѯµÄÉî¶È£¬×îºÃ²»Òª³¬¹ý3²ã¡£
(7)order by £¬group by £¬distinct ÕâЩÓï¾äÔËÐÐʱÏà¶ÔÀ´Ëµ»áÕ¼ÓýϴóµÄÄڴ棬ʹÓÃʱÐèÒª¼ÓÒÔ×¢Òâ¡£
(8)¾¡Á¿ÉÙÓÃNOt£¬°üÀ¨NOT in ºÍnot exist
(9)between 1 and 10 Òª±È in (1,10)×Ö¶ÎÖ´ÐÐЧÂʸߡ£
(10)µ±whereÓï¾äºóÓжà¸ö²éѯÌõ¼þʱ£¬Ó¦¸Ã½«Êý¾ÝÁ¿´óµÄ±íµÄ²éѯ¹ýÂËÌõ¼þ·ÅÔÚÇ°Ãæ¡£
(11)like Óï¾äÊǺܺÄʱµÄ£¬Èç¹ûÌõ¼þÔÊÐíµÄ»°£¬¿ÉÒÔʹÓù¦ÄÜÏàͬµÄÓï¾ä´úÌ棬±ÈÈç
select name from student where ID like '100???'ÕâÌõÓï¾ä£¬»á¶ÔÈ«±í½øÐÐ˳ÐòɨÃ裻¿ÉÒÔ¸ÄΪ select name from student where ID >100000,ÕâÑùÔÚÖ´Ðвéѯʱ¾Í»áÀûÓÃË÷ÒýÀ´²éѯ£¬ÏÔÈ»»á´ó´óÌá¸ßËٶȡ£
(13)¾¡Á¿²»ÒªÔÙSQLÓï¾äÖнøÐжÔÁеIJÙ×÷£¬°üÀ¨Êý¾Ý¿âº¯Êý£¬¼ÆËã±í´ïʽµÈ£¬·ñÔò»áµ¼ÖÂÈ«±íɨÃ裬Ҫ¾¡¿ÉÄܽ«²Ù×÷ÒÆÖÁµÈºÅÓұߡ£
&n
Ïà¹ØÎĵµ£º
±ÜÃâʹÓÃIN ²Ù×÷·û
ÓÃINд³öÀ´µÄSQLµÄÓŵãÊDZȽÏÈÝÒ×д¼°ÇåÎúÒ׶®£¬Õâ±È½ÏÊʺÏÏÖ´úÈí¼þ¿ª·¢µÄ·ç¸ñ¡£
µ«ÊÇÓÃINµÄSQLÐÔÄÜ×ÜÊDZȽϵ͵ģ¬´ÓORACLEÖ´ÐеIJ½ÖèÀ´·ÖÎöÓÃINµÄSQLÓë²»ÓÃINµÄSQLÓÐÒÔÏÂÇø±ð£º
¡¡ORACLEÊÔͼ½«Æäת»»³É¶à¸ö±íµÄÁ¬½Ó£¬Èç¹ûת»»²»³É¹¦ÔòÏÈÖ´ÐÐINÀïÃæµÄ×Ó²éѯ£¬ÔÙ²éѯÍâ²ãµÄ±í¼Ç ......
SELECT DISTINCT '['+user_name(b.uid)+'].['+b.name+']' AS ¶ÔÏóÃû,b.type AS ÀàÐÍ
from sysdepends a,sysobjects b
WHERE b.id=a.depid
AND a.id=OBJECT_ID('¹ý³ÌÃû');
EXEC SP_DEPENDS '¹ý³ÌÃû'; ......
--SQL Server£º
Select TOP N * from TABLE Order By NewID()
--Access£º
Select TOP N * from TABLE Order By Rnd(ID)
Rnd(ID) ÆäÖеÄIDÊÇ×Ô¶¯±àºÅ×ֶΣ¬¿ÉÒÔÀûÓÃÆäËûÈκÎÊýÖµÀ´Íê³É£¬±ÈÈçÓÃÐÕÃû×Ö¶Î(U ......
½ñÌìÓÃtime Like '2008-06-01%'Óï¾äÀ´²éѯ¸ÃÌìµÄËùÓÐÊý¾Ý£¬±»ÌáʾÓï¾ä´íÎó¡£²éÁËһϲŷ¢ÏÖ¸ÃÄ£ºý²éѯֻÄÜÓÃÓÚStringÀàÐ͵Ä×ֶΡ£
×Ô¼ºÒ²²éÔÄÁËһЩ×ÊÁÏ¡£¹ØÓÚʱ¼äµÄÄ£ºý²éѯÓÐÒÔÏÂÈýÖÖ·½·¨£º
1.Convertת³ÉString,ÔÚÓÃLike²éѯ¡£
select * from table1 where c ......
1¡¢¼òµ¥²éѯ
Çó³öÔÚ1988ÄêÒÔÇ°±»¹ÍÓ¶µÄÏúÊÛÈËÔ±
SELECT NAME
from SALESREPS
WHERE HIRE_DATE<'01-JAN-88'
ÁгöÆäÏúÊÛÁ¿µÍÓÚÏúÊÛÄ¿±êµÄ80%µÄÏúÊÛµã
SELECT CITY,SALES,TAGET
from SALESPEPS
WHERE SALES<0.8*TAGET ......