´óÊý¾ÝÁ¿¸ß²¢·¢µÄÊý¾Ý¿âÓÅ»¯(2)
¶þ¡¢²éѯµÄÓÅ»¯
±£Ö¤ÔÚʵÏÖ¹¦ÄܵĻù´¡ÉÏ£¬¾¡Á¿¼õÉÙ¶ÔÊý¾Ý¿âµÄ·ÃÎÊ´ÎÊý£»Í¨¹ýËÑË÷²ÎÊý£¬¾¡Á¿¼õÉÙ¶Ô±íµÄ·ÃÎÊÐÐÊý,×î
С»¯½á¹û¼¯£¬´Ó¶ø¼õÇáÍøÂ縺µ££»Äܹ»·Ö¿ªµÄ²Ù×÷¾¡Á¿·Ö¿ª´¦Àí£¬Ìá¸ßÿ´ÎµÄÏìÓ¦Ëٶȣ»ÔÚÊý¾Ý´°¿ÚʹÓÃ
SQLʱ£¬¾¡Á¿°ÑʹÓõÄË÷Òý·ÅÔÚÑ¡ÔñµÄÊ×ÁУ»Ëã·¨µÄ½á¹¹¾¡Á¿¼òµ¥£»ÔÚ²éѯʱ£¬²»Òª¹ý¶àµØʹÓÃͨÅä·ûÈç
SELECT * FROM T1Óï¾ä£¬ÒªÓõ½¼¸ÁоÍÑ¡Ôñ¼¸ÁÐÈ磺SELECT COL1,COL2 FROM T1£»ÔÚ¿ÉÄܵÄÇé¿öϾ¡Á¿ÏÞ
Öƾ¡Á¿½á¹û¼¯ÐÐÊýÈ磺SELECT TOP 300 COL1,COL2,COL3 FROM T1,ÒòΪijЩÇé¿öÏÂÓû§ÊDz»ÐèÒªÄÇô¶àµÄ
Êý¾ÝµÄ¡£
ÔÚûÓн¨Ë÷ÒýµÄÇé¿öÏ£¬Êý¾Ý¿â²éÕÒijһÌõÊý¾Ý£¬¾Í±ØÐë½øÐÐÈ«±íɨÃèÁË£¬¶ÔËùÓÐÊý¾Ý½øÐÐÒ»´Î±éÀú£¬²é
ÕÒ³ö·ûºÏÌõ¼þµÄ¼Ç¼¡£ÔÚÊý¾ÝÁ¿±È½ÏСµÄÇé¿öÏ£¬Ò²Ðí¿´²»³öÃ÷ÏԵIJî±ð£¬µ«Êǵ±Êý¾ÝÁ¿´óµÄÇé¿öÏ£¬Õâ
ÖÖÇé¿ö¾ÍÊǼ«ÎªÔã¸âµÄÁË¡£
SQLÓï¾äÔÚSQL SERVERÖÐÊÇÈçºÎÖ´Ðеģ¬ËûÃǵ£ÐÄ×Ô¼ºËùдµÄSQLÓï¾ä»á±»SQL SERVERÎó½â¡£±ÈÈ磺
select * from table1 where name='zhangsan' and tID > 10000
ºÍÖ´ÐÐ:
select * from table1 where tID > 10000 and name='zhangsan'
һЩÈ˲»ÖªµÀÒÔÉÏÁ½ÌõÓï¾äµÄÖ´ÐÐЧÂÊÊÇ·ñÒ»Ñù£¬ÒòΪÈç¹û¼òµ¥µÄ´ÓÓï¾äÏȺóÉÏ¿´£¬ÕâÁ½¸öÓï¾äµÄÈ·ÊDz»
Ò»Ñù£¬Èç¹ûtIDÊÇÒ»¸ö¾ÛºÏË÷Òý£¬ÄÇôºóÒ»¾ä½ö½ö´Ó±íµÄ10000ÌõÒÔºóµÄ¼Ç¼ÖвéÕÒ¾ÍÐÐÁË£»¶øÇ°Ò»¾äÔòÒª
ÏÈ´ÓÈ«±íÖвéÕÒ¿´Óм¸¸öname='zhangsan'µÄ£¬¶øºóÔÙ¸ù¾ÝÏÞÖÆÌõ¼þÌõ¼þtID>10000À´Ìá³ö²éѯ½á¹û¡£
ÊÂʵÉÏ£¬ÕâÑùµÄµ£ÐÄÊDz»±ØÒªµÄ¡£SQL SERVERÖÐÓÐÒ»¸ö¡°²éѯ·ÖÎöÓÅ»¯Æ÷¡±£¬Ëü¿ÉÒÔ¼ÆËã³öwhere×Ó¾äÖÐ
µÄËÑË÷Ìõ¼þ²¢È·¶¨ÄĸöË÷ÒýÄÜËõС±íɨÃèµÄËÑË÷¿Õ¼ä£¬Ò²¾ÍÊÇ˵£¬ËüÄÜʵÏÖ×Ô¶¯ÓÅ»¯¡£ËäÈ»²éѯÓÅ»¯Æ÷¿É
ÒÔ¸ù¾Ýwhere×Ó¾ä×Ô¶¯µÄ½øÐвéѯÓÅ»¯£¬µ«ÓÐʱ²éѯÓÅ»¯Æ÷¾Í»á²»°´ÕÕÄúµÄ±¾Òâ½øÐпìËÙ²éѯ¡£
ÔÚ²éѯ·ÖÎö½×¶Î£¬²éѯÓÅ»¯Æ÷²é¿´²éѯµÄÿ¸ö½×¶Î²¢¾ö¶¨ÏÞÖÆÐèҪɨÃèµÄÊý¾ÝÁ¿ÊÇ·ñÓÐÓá£Èç¹ûÒ»¸ö½×¶Î
¿ÉÒÔ±»ÓÃ×÷Ò»¸öɨÃè²ÎÊý£¨SARG£©£¬ÄÇô¾Í³Æ֮Ϊ¿ÉÓÅ»¯µÄ£¬²¢ÇÒ¿ÉÒÔÀûÓÃË÷Òý¿ìËÙ»ñµÃËùÐèÊý¾Ý¡£
SARGµÄ¶¨Ò壺ÓÃÓÚÏÞÖÆËÑË÷µÄÒ»¸ö²Ù×÷£¬ÒòΪËüͨ³£ÊÇÖ¸Ò»¸öÌض¨µÄÆ¥Å䣬һ¸öÖµµÄ·¶Î§ÄÚµÄÆ¥Åä»òÕßÁ½
¸öÒÔÉÏÌõ¼þµÄANDÁ¬½Ó¡£ÐÎʽÈçÏ£º
ÁÐÃû ²Ù×÷·û <³£Êý »ò ±äÁ¿> »ò <³£Êý »ò ±äÁ¿> ²Ù×÷·û ÁÐÃû
ÁÐÃû¿ÉÒÔ³öÏÖÔÚ²Ù×÷·ûµÄÒ»±ß£¬¶ø³£Êý»ò±äÁ¿³öÏÖÔÚ²Ù×÷·ûµÄÁíÒ»±ß¡£È磺
Name=¡¯ÕÅÈý¡¯
¼Û¸ñ>5000
5000<¼Û¸ñ
Name=¡¯ÕÅÈý¡¯ and ¼Û¸ñ>5000
Èç¹ûÒ»¸ö±í´ïʽ²»ÄÜÂú×ãSARGµÄÐÎʽ£¬ÄÇËü¾ÍÎÞ·¨ÏÞÖÆËÑË÷µÄ·¶Î§ÁË£¬Ò²¾ÍÊÇSQL SERVER±ØÐë¶ÔÿһÐж¼
ÅжÏËüÊÇ·ñÂú×ãWHERE×Ó¾äÖеÄËùÓÐÌõ¼þ¡£ËùÒÔÒ»¸öË÷Òý¶ÔÓÚ²»Âú×ãSARGÐÎʽµÄ±í´ïʽÀ´ËµÊÇÎÞÓõġ£
ËùÒÔ£¬ÓÅ»¯²éѯ×îÖØÒªµÄ¾ÍÊÇ£¬¾¡Á¿Ê¹Óï¾ä·ûºÏ²éѯÓÅ»¯Æ÷µÄ¹æÔò±ÜÃâÈ«±íɨÃè¶øʹÓÃË÷Òý²éѯ¡£
¾ßÌåҪעÒâµÄ£º
1.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖжÔ×ֶνøÐÐ null ÖµÅжϣ¬·ñÔò½«µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè
£¬È磺
select id from t where num is null
¿ÉÒÔÔÚnumÉÏÉèÖÃĬÈÏÖµ0£¬È·±£±íÖÐnumÁÐûÓÐnullÖµ£¬È»ºóÕâÑù²éѯ£º
select id from t where num=0
2.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖÐʹÓÃ!=»ò<>²Ù×÷·û£¬·ñÔò½«ÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè¡£ÓÅ»¯Æ÷½«
ÎÞ·¨Í¨¹ýË÷ÒýÀ´È·¶¨½«ÒªÃüÖеÄÐÐÊý,Òò´ËÐèÒªËÑË÷¸Ã±íµÄËùÓÐÐС£
3.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖÐʹÓà or À´Á¬½ÓÌõ¼þ£¬·ñÔò½«µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃ裬Èç
£º
select id from t where num=10 or num=20
¿ÉÒÔÕâÑù²éѯ£º
select id from t where num=10
union all
select id from t where num=20
4.in ºÍ not in Ò²ÒªÉ÷Óã¬ÒòΪIN»áʹϵͳÎÞ·¨Ê¹ÓÃË÷Òý,¶øÖ»ÄÜÖ±½ÓËÑË÷±íÖеÄÊý¾Ý¡£È磺
select id from t where num in(1,2,3)
¶ÔÓÚÁ¬ÐøµÄÊýÖµ£¬ÄÜÓà between ¾Í²»ÒªÓà in ÁË£º
select id from t where num between 1 and 3
5.¾¡Á¿±ÜÃâÔÚË÷Òý¹ýµÄ×Ö·ûÊý¾ÝÖУ¬Ê¹Ó÷ǴòÍ·×ÖĸËÑË÷¡£ÕâҲʹµÃÒýÇæÎÞ·¨ÀûÓÃË÷Òý¡£
¼ûÈçÏÂÀý×Ó£º
SELECT * FROM T1 WHERE NAME LIKE ¡®%L%¡¯
SELECT * FROM T1 WHERE SUBSTING(NAME,2,1)=¡¯L¡¯
SELECT * FROM T1 WHERE NAME LIKE ¡®L%¡¯
¼´Ê¹NAME×ֶν¨ÓÐË÷Òý£¬Ç°Á½¸ö²éѯÒÀÈ»ÎÞ·¨ÀûÓÃË÷ÒýÍê³É¼Ó¿ì²Ù×÷£¬ÒýÇæ²»µÃ²»¶ÔÈ«±íËùÓÐÊý¾ÝÖðÌõ²Ù
×÷À´Íê³ÉÈÎÎñ¡£¶øµÚÈý¸ö²éѯÄܹ»Ê¹ÓÃË÷ÒýÀ´¼Ó¿ì²Ù×÷¡£
6.±ØҪʱǿÖƲéѯÓÅ»¯Æ÷ʹÓÃij¸öË÷Òý£¬ÈçÔÚ where ×Ó¾äÖÐʹÓòÎÊý£¬Ò²»áµ¼ÖÂÈ«±íɨÃè¡£ÒòΪSQLÖ»ÓÐ
ÔÚÔËÐÐʱ²Å»á½âÎö¾Ö²¿±äÁ¿£¬µ«ÓÅ»¯³ÌÐò²»Äܽ«·ÃÎʼƻ®µÄÑ¡ÔñÍƳٵ½ÔËÐÐʱ£»Ëü±ØÐëÔÚ±àÒëʱ½øÐÐÑ¡Ôñ
¡£È»¶ø£¬Èç¹ûÔÚ±àÒëʱ½¨Á¢·ÃÎʼƻ®£¬±äÁ¿µÄÖµ»¹ÊÇδ֪µÄ£¬Òò¶øÎÞ·¨×÷ΪË÷ÒýÑ¡ÔñµÄÊäÈëÏî¡£ÈçÏÂÃæÓï
¾ä½«½øÐÐÈ«±íɨÃ裺
select id from t where num=@num
¿ÉÒÔ¸ÄΪǿÖƲéѯʹÓÃË÷Òý£º
select id from t with(index(Ë÷ÒýÃû)) where num=@num
7.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖжÔ×ֶνøÐбí´ïʽ²Ù×÷£¬Õ⽫µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè¡£Èç
£º
SELECT * FROM T1 WHERE F1/2=100
Ó¦¸ÄΪ:
SELECT * FROM T1 WHERE F1=100*2
SELECT * FROM RECORD WHERE SUBSTRING(CARD_NO,1,4)=¡¯5378¡¯
Ó¦¸ÄΪ:
SELECT * FROM RECORD WHERE CARD_NO LIKE ¡®5378%¡¯
SELECT member_number, first_name, last_name FROM members
WHERE DATEDIFF(yy,datofbirth,GETDATE()) > 21
Ó¦¸ÄΪ:
SELECT member_number, first_name, last_name FROM members
WHERE dateofbirth < DATEADD(yy,-21,GETDATE())
¼´£ºÈκζÔÁеIJÙ×÷¶¼½«µ¼Ö±íɨÃ裬Ëü°üÀ¨Êý¾Ý¿âº¯Êý¡¢¼ÆËã±í´ïʽµÈµÈ£¬²éѯʱҪ¾¡¿ÉÄܽ«²Ù×÷ÒÆÖÁ
µÈºÅÓұߡ£
8.Ó¦¾¡Á¿±ÜÃâÔÚwhere×Ó¾äÖжÔ×ֶνøÐк¯Êý²Ù×÷£¬Õ⽫µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè¡£È磺
select id from t where substring(name,1,3)='abc'--nameÒÔabc¿ªÍ·µÄid
select id from t where datediff(day,createdate,'2005-11-30')=0--¡®2005-11-30¡¯Éú³ÉµÄid
Ó¦¸ÄΪ:
select id from t where name like 'abc%'
select id from t where createdate>='2005-11-30' and createdate<'2005-12-1'
9.²»ÒªÔÚ where ×Ó¾äÖеġ°=¡±×ó±ß½øÐк¯Êý¡¢ËãÊõÔËËã»òÆäËû±í´ïʽÔËË㣬·ñÔòϵͳ½«¿ÉÄÜÎÞ·¨Õýȷʹ
ÓÃË÷Òý¡£
10.ÔÚʹÓÃË÷Òý×Ö¶Î×÷ΪÌõ¼þʱ£¬Èç¹û¸ÃË÷ÒýÊǸ´ºÏË÷Òý£¬ÄÇô±ØÐëʹÓõ½¸ÃË÷ÒýÖеĵÚÒ»¸ö×Ö¶Î×÷ΪÌõ
¼þʱ²ÅÄܱ£Ö¤ÏµÍ³Ê¹ÓøÃË÷Òý£¬·ñÔò¸ÃË÷Òý½«²»»á±»Ê¹Ó㬲¢ÇÒÓ¦¾¡¿ÉÄܵÄÈÃ×Ö¶Î˳ÐòÓëË÷Òý˳ÐòÏàÒ»ÖÂ
¡£
11.ºÜ¶àʱºòÓà existsÊÇÒ»¸öºÃµÄÑ¡Ôñ£º
elect num from a where num in(select num from b)
ÓÃÏÂÃæµÄÓï¾äÌæ»»£º
select num from a where exists(select 1 from b where num=a.num)
SELECT SUM(T1.C1)FROM T1 WHERE(
(SELECT COUNT(*)FROM T2 WHERE T2.C2=T1.C2>0)
SELECT SUM(T1.C1) FROM T1WHERE EXISTS(
SELECT * FROM T2 WHERE T2.C2=T1.C2)
Á½Õß²úÉúÏàͬµÄ½á¹û£¬µ«ÊǺóÕßµÄЧÂÊÏÔȻҪ¸ßÓÚÇ°Õß¡£ÒòΪºóÕß²»»á²úÉú´óÁ¿Ëø¶¨µÄ±íɨÃè»òÊÇË÷Òýɨ
Ãè¡£
Èç¹ûÄãÏëУÑé±íÀïÊÇ·ñ´æÔÚijÌõ¼Í¼£¬²»ÒªÓÃcount(*)ÄÇÑùЧÂʺܵͣ¬¶øÇÒÀË·Ñ·þÎñÆ÷×ÊÔ´¡£¿ÉÒÔÓÃ
EXISTS´úÌæ¡£È磺
IF (SELECT COUNT(*) FROM table_name WHERE column_name = 'xxx')
¿ÉÒÔд³É£º
IF EXISTS (SELECT * FROM table_name WHERE column_name = 'xxx')
¾³£ÐèҪдһ¸öT_SQLÓï¾ä±È½ÏÒ»¸ö¸¸½á¹û¼¯ºÍ×Ó½á¹û¼¯£¬´Ó¶øÕÒµ½ÊÇ·ñ´æÔÚÔÚ¸¸½á¹û¼¯ÖÐÓжøÔÚ×Ó½á¹û
¼¯ÖÐûÓеļǼ£¬È磺
SELECT a.hdr_key FROM hdr_tbl a---- tbl a ±íʾtblÓñðÃûa´úÌæ
WHERE NOT EXISTS (SELECT * FROM dtl_tbl b WHERE a.hdr_key = b.hdr_key)
SELECT a.hdr_key FROM hdr_tbl a
LEFT JOIN dtl_tbl b ON a.hdr_key = b.hdr_key WHERE b.hdr_key IS NULL
SELECT hdr_key FROM hdr_tbl
WHERE hdr_key NOT IN (SELECT hdr_key FROM dtl_tbl)
ÈýÖÖд·¨¶¼¿ÉÒԵõ½Í¬ÑùÕýÈ·µÄ½á¹û£¬µ«ÊÇЧÂÊÒÀ´Î½µµÍ¡£
12.¾¡Á¿Ê¹Óñí±äÁ¿À´´úÌæÁÙʱ±í¡£Èç¹û±í±äÁ¿°üº¬´óÁ¿Êý¾Ý£¬Çë×¢ÒâË÷Òý·Ç³£ÓÐÏÞ£¨Ö»ÓÐÖ÷¼üË÷Òý£©¡£
13.±ÜÃâƵ·±´´½¨ºÍɾ³ýÁÙʱ±í£¬ÒÔ¼õÉÙϵͳ±í×ÊÔ´µÄÏûºÄ¡£
14.ÁÙʱ±í²¢²»ÊDz»¿ÉʹÓã¬Êʵ±µØʹÓÃËüÃÇ¿ÉÒÔʹijЩÀý³Ì¸üÓÐЧ£¬ÀýÈ磬µ±ÐèÒªÖظ´ÒýÓôóÐͱí»ò³£
ÓñíÖеÄij¸öÊý¾Ý¼¯Ê±¡£µ«ÊÇ£¬¶ÔÓÚÒ»´ÎÐÔʼþ£¬×îºÃʹÓõ¼³ö±í¡£
15.ÔÚн¨ÁÙʱ±íʱ£¬Èç¹ûÒ»´ÎÐÔ²åÈëÊý¾ÝÁ¿ºÜ´ó£¬ÄÇô¿ÉÒÔʹÓà select into ´úÌæ create table£¬±Ü
ÃâÔì³É´óÁ¿ log £¬ÒÔÌá¸ßËٶȣ»Èç¹ûÊý¾ÝÁ¿²»´ó£¬ÎªÁË»ººÍϵͳ±íµÄ×ÊÔ´£¬Ó¦ÏÈcreate table£¬È»ºó
insert¡£
16.Èç¹ûʹÓõ½ÁËÁÙʱ±í£¬ÔÚ´æ´¢¹ý³ÌµÄ×îºóÎñ±Ø½«ËùÓеÄÁÙʱ±íÏÔʽɾ³ý£¬ÏÈ truncate table £¬È»ºó
drop table £¬ÕâÑù¿ÉÒÔ±ÜÃâϵͳ±íµÄ½Ï³¤Ê±¼äËø¶¨¡£
17.ÔÚËùÓеĴ洢¹ý³ÌºÍ´¥·¢Æ÷µÄ¿ªÊ¼´¦ÉèÖà SET NOCOUNT ON £¬ÔÚ½áÊøʱÉèÖà SET NOCOUNT OFF ¡£ÎÞÐè
ÔÚÖ´Ðд洢¹ý³ÌºÍ´¥·¢Æ÷µÄÿ¸öÓï¾äºóÏò¿Í»§¶Ë·¢ËÍ DONE_IN_PROC ÏûÏ¢¡£
18.¾¡Á¿±ÜÃâ´óÊÂÎñ²Ù×÷£¬Ìá¸ßϵͳ²¢·¢ÄÜÁ¦¡£
19.¾¡Á¿±ÜÃâÏò¿Í»§¶Ë·µ»Ø´óÊý¾ÝÁ¿£¬ÈôÊý¾ÝÁ¿¹ý´ó£¬Ó¦¸Ã¿¼ÂÇÏàÓ¦ÐèÇóÊÇ·ñºÏÀí¡£
20. ±ÜÃâʹÓò»¼æÈݵÄÊý¾ÝÀàÐÍ¡£ÀýÈçfloatºÍint¡¢charºÍvarchar¡¢binaryºÍvarbinaryÊDz»¼æÈݵġ£Êý
¾ÝÀàÐ͵IJ»¼æÈÝ¿ÉÄÜʹÓÅ»¯Æ÷ÎÞ·¨Ö´ÐÐһЩ±¾À´¿ÉÒÔ½øÐеÄÓÅ»¯²Ù×÷¡£ÀýÈç:
SELECT name FROM employee WHERE salary > 60000
ÔÚÕâÌõÓï¾äÖÐ,Èçsalary×Ö¶ÎÊÇmoneyÐ͵Ä,ÔòÓÅ»¯Æ÷ºÜÄѶÔÆä½øÐÐÓÅ»¯,ÒòΪ60000ÊǸöÕûÐÍÊý¡£ÎÒÃÇÓ¦µ±
ÔÚ±à³Ìʱ½«ÕûÐÍת»¯³ÉΪǮ±ÒÐÍ,¶ø²»ÒªµÈµ½ÔËÐÐʱת»¯¡£
21.³ä·ÖÀûÓÃÁ¬½ÓÌõ¼þ£¬ÔÚijÖÖÇé¿öÏ£¬Á½¸ö±íÖ®¼ä¿ÉÄܲ»Ö»Ò»¸öµÄÁ¬½ÓÌõ¼þ£¬ÕâʱÔÚ WHERE ×Ó¾äÖн«Á¬
½ÓÌõ¼þÍêÕûµÄдÉÏ£¬ÓпÉÄÜ´ó´óÌá¸ß²éѯËٶȡ£
Àý£º
SELECT SUM(A.AMOUNT) FROM ACCOUNT A,CARD B WHERE A.CARD_NO = B.CARD_NO
SELECT SUM(A.AMOUNT) FROM ACCOUNT A,CARD B WHERE A.CARD_NO = B.CARD_NO AND
A.ACCOUNT_NO=B.ACCOUNT_NO
µÚ¶þ¾ä½«±ÈµÚÒ»¾äÖ´ÐпìµÃ¶à¡£
22¡¢Ê¹ÓÃÊÓͼ¼ÓËÙ²éѯ
°Ñ±íµÄÒ»¸ö×Ó¼¯½øÐÐÅÅÐò²¢´´½¨ÊÓͼ£¬ÓÐʱÄܼÓËÙ²éѯ¡£ËüÓÐÖúÓÚ±ÜÃâ¶àÖØÅÅÐò ²Ù×÷£¬¶øÇÒÔÚÆäËû·½Ãæ
»¹Äܼò»¯ÓÅ»¯Æ÷µÄ¹¤×÷¡£ÀýÈ磺
SELECT cust.name£¬rcvbles.balance£¬¡¡other columns
FROM cust£¬rcvbles
WHERE cust.customer_id = rcvlbes.customer_id
AND rcvblls.balance>0
AND cust.postcode>¡°98000¡±
ORDER BY cust.name
Èç¹ûÕâ¸ö²éѯҪ±»Ö´Ðжà´Î¶ø²»Ö¹Ò»´Î£¬¿ÉÒÔ°ÑËùÓÐδ¸¶¿îµÄ¿Í»§ÕÒ³öÀ´·ÅÔÚÒ»¸öÊÓͼÖУ¬²¢°´¿Í»§µÄÃû
×Ö½øÐÐÅÅÐò£º
CREATE VIEW DBO.V_CUST_RCVLBES
AS
SELECT cust.name£¬rcvbles.balance£¬¡¡other columns
FROM cust£¬rcvbles
WHERE cust.customer_id = rcvlbes.customer_id
AND rcvblls.balance>0
ORDER BY cust.name
È»ºóÒÔÏÂÃæµÄ·½Ê½ÔÚÊÓͼÖвéѯ£º
SELECT £ª FROM V_CUST_RCVLBES
WHERE postcode>¡°98000¡±
ÊÓͼÖеÄÐÐÒª±ÈÖ÷±íÖеÄÐÐÉÙ£¬¶øÇÒÎïÀí˳Ðò¾ÍÊÇËùÒªÇóµÄ˳Ðò£¬¼õÉÙÁË´ÅÅÌI/O£¬ËùÒÔ²éѯ¹¤×÷Á¿¿ÉÒÔ
µÃµ½´ó·ù¼õÉÙ¡£
23¡¢ÄÜÓÃDISTINCTµÄ¾Í²»ÓÃGROUP BY
SELECT OrderID FROM Details WHERE UnitPrice > 10 GROUP BY OrderID
¿É¸ÄΪ£º
SELECT DISTINCT OrderID FROM Details WHERE UnitPrice > 10
24.ÄÜÓÃUNION ALL¾Í²»ÒªÓÃUNION
UNION ALL²»Ö´ÐÐSELECT DISTINCTº¯Êý£¬ÕâÑù¾Í»á¼õÉٺܶ಻±ØÒªµÄ×ÊÔ´
35.¾¡Á¿²»ÒªÓÃSELECT INTOÓï¾ä¡£
SELECT INOT Óï¾ä»áµ¼Ö±íËø¶¨£¬×èÖ¹ÆäËûÓû§·ÃÎÊ¸Ã±í¡£
ÉÏÃæÎÒÃÇÌáµ½µÄÊÇһЩ»ù±¾µÄÌá¸ß²éѯËٶȵÄ×¢ÒâÊÂÏî,µ«ÊÇÔÚ¸ü¶àµÄÇé¿öÏÂ,ÍùÍùÐèÒª·´¸´ÊÔÑé±È½Ï
²»Í¬µÄÓï¾äÒԵõ½×î¼Ñ·½°¸¡£×îºÃµÄ·½·¨µ±È»ÊDzâÊÔ£¬¿´ÊµÏÖÏàͬ¹¦ÄܵÄSQLÓï¾äÄĸöÖ´ÐÐʱ¼ä×îÉÙ£¬µ«
ÊÇÊý¾Ý¿âÖÐÈç¹ûÊý¾ÝÁ¿ºÜÉÙ£¬ÊDZȽϲ»³öÀ´µÄ£¬Õâʱ¿ÉÒÔÓò鿴ִÐмƻ®£¬¼´£º°ÑʵÏÖÏàͬ¹¦ÄܵĶàÌõ
SQLÓï¾ä¿¼µ½²éѯ·ÖÎöÆ÷£¬°´CTRL+L¿´²éËùÀûÓõÄË÷Òý£¬±íɨÃè´ÎÊý£¨ÕâÁ½¸ö¶ÔÐÔÄÜÓ°Ïì×î´ó£©£¬×ÜÌåÉÏ
¿´Ñ¯³É±¾°Ù·Ö±È¼´¿É¡£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ