¼òµ¥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
Ïà¹ØÎĵµ£º
¶ÔÓÚ³õѧÕ߶Դ¥·¢Æ÷µÄÀí½âÍùÍù²»ÊǺÜ͸³¹£¬¼ÇµÃ×Ô¼ºµ±³õѧµÄʱºò×ÜÓеãÃþ²»ÇåÍ·ÄԵĸоõ£¬½ñÌì¾ÍÏëÆðºÍ´ó¼Ò×ܽáһϣ¬Èç¹ûÎÄÕ³öÏÖЩ覴ÃÇë¸ßÊÖ¶à¶àÖ¸½ÌŶ£¡
´¥·¢Æ÷ÊÇÊý¾Ý¿â·þÎñÆ÷Öз¢Éúʼþʱ×Ô¶¯Ö´ÐеÄÌØÊâ´æ´¢¹ý³Ì£¬Ëü²åÈ롢ɾ³ý»òÐÞ¸ÄÌرíÖеÄÊý¾Ýʱ´¥·¢Ö´ÐС£´¥·¢Æ÷ͨ³£¿ÉÒÔÇ¿ÖÆÖ´ÐÐÒ»¶¨µÄÒµÎñ¹æÔò£¬ÒÔ±£³ÖÊý¾ÝÍêÕûÐÔ ......
ÔÚ×ö“¶¼ÊмÒÔ°”ÓÅ»¯Ê±£¬¾ßÌåÊÇÓû§×¢²áʱ£¬Ìá½»ÐÅÏ¢£¬±¾À´BirthdayÊÇûÓÐдÈëÖµµÄ£¬´Ë×Ö¶ÎҲûÓÐĬÈÏÖµ£¬¿ÉÊý¾Ý¿âÖÐȴΪ“1905/3/14 0:00:00”£¬ÓôÃÆÖÁ¼«£¬ÉÏgoogle&baiduÒ²ÊÇûÓнâ¾öµÄ·½°¸¡£
Ö»ÄÜÕâÑùÔʼµÄ½â¾ö£º
Register ´æ´¢¹ý³Ì
insert into UserInfo(UserID,sex) ......
¿ª·¢Êý¾Ý¿âÓ¦Óã¬Ñ¡ÔñÒ»¸öºÃµÄÊý¾Ý¿âÊǷdz£ÖØÒªµÄ¡£±¾ÎÄ´ÓһЩ·½Ãæ±È½ÏÁËSQL ServerÓëOracle¡¢DB2ÈýÖÖÊý¾Ý¿â£¬ÎªÄãÑ¡ÔñÊý¾Ý¿âÌṩһЩ²Î¿¼¡£
¡¡¡¡
¡¡¡¡¿ª·ÅÐÔ
¡¡¡¡SQL Server
¡¡¡¡Ö»ÄÜÔÚWindows ÉÏÔËÐУ¬Ã»ÓÐË¿ºÁµÄ¿ª·ÅÐÔ£¬²Ù×÷ϵͳµÄϵͳµÄÎȶ¨¶ÔÊý¾Ý¿âÊÇÊ®·ÖÖØÒªµÄ¡£Windows9XϵÁвúÆ·ÊÇÆ«ÖØÓÚ×ÀÃæÓ¦Óã¬NT se ......
´æ´¢½ø³Ì¾ÍÊÇ×÷Ϊ¿ÉÖ´ÐжÔÏó´æ·ÅÔÚÊý¾Ý¿âÖеÄÒ»¸ö»ò¶à¸öSQLÃüÁî¡£
¶¨Òå×ÜÊǺܳéÏó¡£´æ´¢½ø³ÌÆäʵ¾ÍÊÇÄÜÍê³ÉÒ»¶¨²Ù×÷µÄÒ»×éSQLÓï¾ä£¬Ö»²»¹ýÕâ×éÓï¾äÊÇ·ÅÔÚÊý¾Ý¿âÖеÄ(ÕâÀïÎÒÃÇ̸ֻSQL SERVER)¡£Èç¹ûÎÒÃÇͨ¹ý´´½¨´æ´¢½ø³ÌÒÔ¼°ÔÚASPÖе÷Óô洢½ø³Ì£¬¾Í¿ÉÒÔ±ÜÃ⽫SQLÓï¾äͬASP´úÂë»ìÔÓÔÚÒ ......
ÔÚASP.NetÏîÄ¿ÖÐʹÓô洢¹ý³Ì,Ê×ÏÈ¿ÉÒÔÌá¸ßÊý¾Ý¿âµÄ°²È«ÐÔ£¬Æä´Î¿ÉÒÔÌá¸ßÔËÐÐSQL´úÂëÔËÐеÄËٶȣ¬ÔÚ´óÐÍÏîÄ¿ÖÐÒ»°ãÊDZز»¿ÉÉٵġ£Visual Studio.NetΪSQLµÄ´æ´¢¹ý³ÌÌṩÁËÇ¿´óµÄÖ§³Ö£¬Äú¼È¿ÉÒÔͨ¹ývisual studio.netÀ´Ð½¨´æ´¢¹ý³Ì£¬Ò²¿ÉÒÔÖ±½ÓÔÚSql ServerµÄ²éѯ·ÖÎöÆ÷ÖÐÔËÐУ¬»¹¿ÉÒÔͨ¹ýÆóÒµ¹ÜÀíÆ÷´´½¨£¬Ê¹ÓÃÆðÀ´Ò² ......