¼òµ¥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
Ïà¹ØÎĵµ£º
¾ßÌå³ö´¦²»Ïê¡£
ÈçºÎÈÃÄãµÄSQLÔËÐеøü¿ì
---- ÈËÃÇÔÚʹÓÃSQLʱÍùÍù»áÏÝÈëÒ»¸öÎóÇø£¬¼´Ì«¹Ø×¢ÓÚËùµÃµÄ½á¹ûÊÇ·ñÕýÈ·£¬¶øºöÂÔÁ˲»Í¬µÄʵÏÖ·½·¨Ö®¼ä¿ÉÄÜ´æÔÚµÄÐÔÄܲîÒ죬ÕâÖÖÐÔÄܲîÒìÔÚ´óÐ͵ĻòÊǸ´ÔÓµÄÊý¾Ý¿â»·¾³ÖУ¨ÈçÁª»úÊÂÎñ´¦ÀíOLTP»ò¾ö²ßÖ§³ÖϵͳDSS£©ÖбíÏÖµÃÓÈΪÃ÷ÏÔ¡£±ÊÕßÔÚ¹¤×÷ʵ¼ùÖз¢ÏÖ£¬²»Á¼µÄSQLÍùÍùÀ´×ÔÓÚ² ......
1.select * into [±í] from OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 5.0;HDR=YES;DATABASE=D:\VFP\jspg\QuickEval2.5\Export\20092\dgqxps.xls',dgqxps$)
ÈôÓöµ½SQL Server ×èÖ¹Á˶Ô×é¼þ 'Ad Hoc Distributed Queries' µÄ STATEMENT'OpenRowset/OpenDatasource' µÄ·ÃÎÊ£¬ÒòΪ´Ë×é¼þÒÑ×÷Ϊ´Ë·þÎñÆ÷°²È«ÅäÖõÄÒ»²¿·Ö¶ø ......
ͨ¹ý“Ìí¼Óɾ³ý³ÌÐò”Àï²¢²»ÄÜÍêȫɾ³ýSQlL server¡£
ͨ¹ýÏÂÃæµÄÃüÁÍêÈ«·´°²×°SQL server 2005
d:\Setup.exe
/
qb REMOVE
=ALL
INSTANCENAME
=<
InstanceName
>
ĬÈÏʵÀýµÄÃû×ÖÊÇMSSQLSERVER
ÒýÓÃÎÄÕµØÖ·£ºhttp://www.cnblogs.com/jvstudio/archive/2010/01/17/1650089.ht ......
Ò».Ãû´Ê½âÊÍ£º
0¡£SQL ½á¹¹»¯²éѯÓïÑÔ(Structured Query Language)
1¡£·Ç¹ØϵÐÍÊý¾Ý¿âϵͳ
×öΪµÚÒ»´úÊý¾Ý¿âϵͳµÄ×ܳƣ¬Æä°üÀ¨2ÖÖÀàÐÍ£º“²ã´Î”Êý¾Ý¿âÓë“Íø×´”Êý¾Ý¿â
“²ã´Î”Êý¾Ý¿â¹ÜÀíϵͳ eg:IBM&IMS (Information Management System ......
1.ORACLE²ÉÓÃ×Ô϶øÉϵÄ˳Ðò½âÎöWHERE×Ó¾ä,¸ù¾ÝÕâ¸öÔÀí,±íÖ®¼äµÄÁ¬½Ó±ØÐëдÔÚÆäËûWHEREÌõ¼þ֮ǰ, ÄÇЩ¿ÉÒÔ¹ýÂ˵ô×î´óÊýÁ¿¼Ç¼µÄÌõ¼þ±ØÐëдÔÚWHERE×Ó¾äµÄĩβ.
(µÍЧ)
SELECT … from EMP E WHERE SAL > 50000 AND JOB = ‘MANAGER’ AND 25 < (SELECT COUNT(*) from EMP WHERE MGR=E. ......