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

¼òµ¥SQLÓï¾äС½á

ΪÁË´ó¼Ò¸üÈÝÒ×Àí½âÎÒ¾Ù³öµÄSQLÓï¾ä£¬±¾Îļٶ¨ÒѾ­½¨Á¢ÁËÒ»¸öѧÉú³É¼¨¹ÜÀíÊý¾Ý¿â£¬È«ÎľùÒÔѧÉú³É¼¨µÄ¹ÜÀíΪÀýÀ´ÃèÊö¡£
¡¡¡¡1.ÔÚ²éѯ½á¹ûÖÐÏÔʾÁÐÃû£º
¡¡¡¡a.ÓÃas¹Ø¼ü×Ö£ºselect name as 'ÐÕÃû' from students order by age
¡¡¡¡b.Ö±½Ó±íʾ£ºselect name 'ÐÕÃû' from students order by age
¡¡¡¡2.¾«È·²éÕÒ:
¡¡¡¡a.ÓÃinÏÞ¶¨·¶Î§£ºselect * from students where native in ('ºþÄÏ', 'ËÄ´¨')
¡¡¡¡b.between...and£ºselect * from students where age between 20 and 30
¡¡¡¡c.“=”£ºselect * from students where name = 'Àîɽ'
¡¡¡¡d.like:select * from students where name like 'Àî%' (×¢Òâ²éѯÌõ¼þÖÐÓГ%”£¬Ôò˵Ã÷ÊDz¿·ÖÆ¥Å䣬¶øÇÒ»¹ÓÐÏȺóÐÅÏ¢ÔÚÀïÃæ£¬¼´²éÕÒÒÔ“ÀªÍ·µÄÆ¥ÅäÏî¡£ËùÒÔÈô²éѯÓГÀÄËùÓжÔÏó£¬Ó¦¸ÃÃüÁ'%Àî%';ÈôÊǵڶþ¸ö×ÖΪÀÔòӦΪ'_Àî%'»ò'_Àî'»ò'_Àî_'¡£)
¡¡¡¡e.[]Æ¥Åä¼ì²é·û£ºselect * from courses where cno like '[AC]%' (±íʾ»òµÄ¹ØÏµ£¬Óë"in(...)"ÀàËÆ£¬¶øÇÒ"[]"¿ÉÒÔ±íʾ·¶Î§£¬È磺select * from courses where cno like '[A-C]%')
¡¡¡¡3.¶ÔÓÚʱ¼äÀàÐͱäÁ¿µÄ´¦Àí
¡¡¡¡a.smalldatetime£ºÖ±½Ó°´ÕÕ×Ö·û´®´¦ÀíµÄ·½Ê½½øÐд¦Àí£¬ÀýÈ磺
select * from students where birth > = '1980-1-1' and birth <= '1980-12-31'
¡¡¡¡4.¼¯º¯Êý
¡¡¡¡a.count()ÇóºÍ£¬È磺select count(*) from students (ÇóѧÉú×ÜÈËÊý)
¡¡¡¡b.avg(ÁÐ)Ç󯽾ù£¬È磺select avg(mark) from grades where cno=’B2’
¡¡¡¡c.max(ÁÐ)ºÍmin(ÁÐ)£¬Çó×î´óÓë×îС
¡¡¡¡5.·Ö×égroup
¡¡¡¡³£ÓÃÓÚͳ¼ÆÊ±£¬Èç·Ö×é²é×ÜÊý£º
select gender,count(sno)
from students
group by gender
(²é¿´ÄÐŮѧÉú¸÷ÓжàÉÙ)
¡¡¡¡×¢Ò⣺´ÓÄÄÖֽǶȷÖ×é¾Í´ÓÄÄÁÐ"group by"
¡¡¡¡¶ÔÓÚ¶àÖØ·Ö×飬ֻÐ轫·Ö×鹿ÔòÂÞÁС£±ÈÈç²éѯ¸÷½ì¸÷רҵµÄÄÐŮͬѧÈËÊý £¬ÄÇô·Ö×鹿ÔòÓУº½ì±ð(grade)¡¢×¨Òµ(mno)ºÍÐÔ±ð(gender)£¬ËùÒÔÓÐ"group by grade, mno, gender"
select grade, mno, gender, count(*)
from students
group by grade, mno, gender
¡¡¡¡Í¨³£group»¹ºÍhavingÁªÓ㬱ÈÈç²éѯ1ÃÅ¿ÎÒÔÉϲ»¼°¸ñµÄѧÉú£¬Ôò°´Ñ§ºÅ(sno)·ÖÀàÓУº
select sno,count(*) from grades
where mark<60
group by sno
having count(*)>1
¡¡¡¡6.UNIONÁªºÏ
¡¡¡¡ºÏ²¢²éѯ½á¹û£¬È磺
SELECT * from students
W


Ïà¹ØÎĵµ£º

ASP³ÌÐòÓëSQL´æ´¢¹ý³ÌÏê½â

  ´æ´¢½ø³Ì¾ÍÊÇ×÷Ϊ¿ÉÖ´ÐжÔÏó´æ·ÅÔÚÊý¾Ý¿âÖеÄÒ»¸ö»ò¶à¸öSQLÃüÁî¡£
    ¶¨Òå×ÜÊǺܳéÏó¡£´æ´¢½ø³ÌÆäʵ¾ÍÊÇÄÜÍê³ÉÒ»¶¨²Ù×÷µÄÒ»×éSQLÓï¾ä£¬Ö»²»¹ýÕâ×éÓï¾äÊÇ·ÅÔÚÊý¾Ý¿âÖеÄ(ÕâÀïÎÒÃÇ̸ֻSQL SERVER)¡£Èç¹ûÎÒÃÇͨ¹ý´´½¨´æ´¢½ø³ÌÒÔ¼°ÔÚASPÖе÷Óô洢½ø³Ì£¬¾Í¿ÉÒÔ±ÜÃ⽫SQLÓï¾äͬASP´úÂë»ìÔÓÔÚÒ ......

SQLϰÌâ3

µÚ¶þÊ®Ì⣺
ÔõôÑù³éÈ¡ÖØ¸´¼Ç¼
񡜧
id name
--------
1 test1
2 test2
3 test3
4 test4
5 test5
6 test6
2 test2
3 test3
2 test2
6 test6
²é³öËùÓÐÓÐÖØ¸´¼Ç¼µÄÊý¾Ý£¬ÓÃÒ»¾äsql À´ÊµÏÖ
create table D(
id varchar (20),
name varchar (20)
)
insert into D values('1','test1')
insert into D val ......

SqlÐÔÄÜÓÅ»¯

 
²Ù×÷·ûÓÅ»¯
IN ²Ù×÷·û
ÓÃINд³öÀ´µÄSQLµÄÓŵãÊDZȽÏÈÝÒ×д¼°ÇåÎúÒ×¶®£¬Õâ±È½ÏÊʺÏÏÖ´úÈí¼þ¿ª·¢µÄ·ç¸ñ¡£
µ«ÊÇÓÃINµÄSQLÐÔÄÜ×ÜÊDZȽϵ͵쬴ÓORACLEÖ´ÐеIJ½ÖèÀ´·ÖÎöÓÃINµÄSQLÓë²»ÓÃINµÄSQLÓÐÒÔÏÂÇø±ð£º
ORACLEÊÔͼ½«Æäת»»³É¶à¸ö±íµÄÁ¬½Ó£¬Èç¹ûת»»²»³É¹¦ÔòÏÈÖ´ÐÐINÀïÃæµÄ×Ó²éѯ£¬ÔÙ²éѯÍâ²ãµÄ±í¼Ç¼£¬Èç¹ûת»»³ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ