ÓйØSQLÖÐÂß¼²éѯ´¦ÀíµÄ¸÷¸ö½×¶Î£¨×Ô¼º¸ãµÄÀý×Ó£¬²»¶ÔµÄ»¶ÓÖ¸ÕýŶ£©
SQL²»Í¬ÓÚÆäËûµÄ±à³ÌÓïÑÔµÄ×î´ó×î´óÌØÕ÷ÓÐ3¸ö°É£¬
Ò»¸öÊÇËüÊÇÃæÏò¼¯ºÏµÄ±à³Ì˼Ï룬µÚ¶þ¸öÊÇÈýÖµÂß¼£¨Õâ¸öºóÃæ»á˵µ½£©£¬»¹ÓÐÒ»¸ö¾ÍÊǽñÌìÖ÷ҪҪ˵µÄ²éѯԪËصÄÂß¼´¦Àí´ÎÐò¡£
Çë¿´Ò»¸ö»ù±¾²éѯµÄÂß¼¹ý³Ì£º
(8) SELECT (9) DISTINCT (11) <TOP_specification> <select_list>
(1) from <left_table>
(3) <join_type> JOIN <right_table>
(2) ON <join_condition>
(4) WHERE <where_condition>
(5) GROUP BY <group_by_list>
(6) WITH {CUBE | ROLLUP}
(7) HAVING <having_condition>
(10) ORDER BY <order_by_list>
´ó¼Ò¿ÉÒÔ¿´µ½ ÕâÀïµÄÔËÐв½Öè²»ÊÇÏñÒ»°ãµÄ±à³Ì Ò»¾ä¾ä´ÓÉÏÍùÏ ËüÊÇÌø¶¯µÄ ÓлîÁ¦µÄ
ÕâÀïÌáǰ˵Ï ÿһ²½¶¼»á²úÉúÒ»¸öÐéÄâµÄ±í£¨Ò²¿ÉÄÜÊÇÓα꣬ÏÂÃæ»áÌáµ½£©£¬×÷ΪÏÂÒ»¸ö²½ÖèµÄÊäÈë¡£´ó¼Ò×îºó¿´µ½µÄ½á¹ûÆäʵ¾ÍÊÇ×îºóÒ»¸öÐéÄâ±íÁË¡£
ºÃÁË£¬ÏÂÃæÎÒ¿ªÊ¼¾ßÌå²ûÊÍÿ¸ö²½Ö裺
²âÊÔ»·¾³£º
--ÌâÄ¿ÒªÇó£ºÇó³öѧÉú×îµÍ¿ÆÄ¿³É¼¨²»µÍÓÚ90·ÖÇÒÄêÁäÔÚ7ËêÒÔÉϵÄѧÉúÐÕÃû
create table #student(s# int,sname varchar(10),age int)
create table #study (s# int, c# char(1),score int)
insert #student
1,'xiaozhu',10 union all select
2,'xiaomao' ,9union all select
3,'xiaozhe' ,7union all select
4,'xiaophai',8 union all select
5,'xiaoduo',9
insert #study select
1,'A',99 union all select
1,'B',90 union all select
1,'C',99 union all select
2,'A',99 union all select
2,'b',99 union all select
2,'c',98 union all select
3,'A',99 union all select
3,'b',92 union all select
3,'c',91 union all select
3,'d',90 union all select
4,'A',88 union all select
4,'B',96
--SQLÓï¾ä
select top 1 sname,MIN(score) as minsocre
from #student s left outer join #study sc
on s.s#=sc.s#
where age>7
group by sname
having MIN(score)>=90
order by minsocre
/*
sname minsocre
---------- -----------
xiaozhu 90
*/
(1)£ºÖ´Ðеѿ¨¶û»ý£¨CROSS JOIN £©
´ó¼ÒÕâ
¡¡×î½üΪÊý¾Ý¿â·þÎñÆ÷Ôö¼ÓÁËÄڴ棬´ïµ½ÁË×î´óÖ§³ÖµÄ8G£¬Êý¾Ý¿âÓõÄÊÇmssql 2005 £¬Ö®Ç°ÄÚ´æÒ»Ö±ÊÇ4GµÄ£¬²»´æÔÚÄÚ´æ´óºÍ32λ²Ù×÷ϵͳ³åÍ»µÄÊÂÇ飬32λ²Ù×÷ϵͳµ¥½ø³Ì×î´óÖ§³Ö2GµÄÄڴ棬ÕâÑù×ӵĻ°ÄÚ´æ¾Í°×¼ÓÁË£¬Ôõô°ìÄØ?
¡¡¡¡ÍøÉÏËÑË÷Á˺ܶà×ÊÁÏ£¬·¢ÏÖ΢ÈíÌṩÁËÒ»¸öËãÊÇÁÙʱµÄ½â¾ö·½°¸°É£¬Ê¹ÓÃAWEÀ´·ÖÅäÄڴ棬ÕâÑù×Ósqlse ......
Êý¾Ý¿âÊÂÎñÊÇÆäËûÊÂÎñÄ£Ð͵Ļù´¡£¬µ±Ò»¸öÊÂÎñ´´½¨Ê±²»Í¬Êý¾Ý¿âϵͳ¶¼ÓÐ×Ô¼ºµÄ¹æ
Ôò¡£SQL Server ĬÈÏÔÚ×Ô¶¯Ìá½»µÄģʽϹ¤×÷£¬Ã¿¸öÓï¾äÖ´ÐÐÍêºó¶¼»áÁ¢¼´Ìá½»£»Óë´Ë¶ÔÕÕ
µÄÊÇ Oracle ÐèÒªÄã°üº¬Ò»¸öÌá½»Óï¾ä¡£µ«Êǵ±Ò»¸öÓï¾äͨ¹ý OLE DB Ö´ÐÐʱ£¬ËüÖ´ÐÐÍêºó
Ò»¸öÌá½»¶¯×÷»á±»¸½¼ÓÉÏÈ¥¡£ÀýÈ磺
DECLARE  ......