SQLÖÐÂß¼²éѯ´¦ÀíµÄ¸÷¸ö½×¶Î
ÓйØ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 £©
´ó¼ÒÕâ
Ïà¹ØÎĵµ£º
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ
......
2.¸ù¾ÝOracle Êý¾Ý¿âscott ģʽϵÄemp ±íºÍdept ±í£¬Íê³ÉÏÂÁвÙ×÷£º
(1) ²éѯ20ºÅ²¿ÃŵÄËùÓÐÔ±¹¤ÐÅÏ¢£»
(2) ²éѯËùÓй¤ÖÖΪCLERK µÄÔ±¹¤µÄÔ±¹¤ºÅ¡¢Ô±¹¤ÃûºÍ²¿Ãźţ»
(3) ²éѯ½±½ðCOMM ¸ßÓÚ¹¤×ÊSAL µÄÔ±¹¤ÐÅÏ¢£»
  ......
ÔÚÐ¶ÔØVisual Studio 2008 ʱ£¬Ìí¼Ó/ɾ³ý³ÌÐò ÀïÃæÓÐÐí¶àµÄ°²×°Îļþ£¬´ËʱÈç¹ûûÓÐÏÈÐ¶ÔØSQL Server 2005 £¬
¶øÏÈÐ¶ÔØ.Net Framework£¨Ìáʾ£ºÐ¶ÔØ.net FrameworkµÄµÃ°²°æ±¾´Ó¸ßµ½µÍµÄ˳Ðò£©£¬
ÕâʱSQL Server 2005¾Í²»ÄÜÐ¶ÔØ,ɾ³ýProgram files ÏÂÃæµÄ Microsoft SQL Server Îļþ¼ÐҲûÓÐ×÷Óá£
ÖØÐ°²×°ÌáʾÊý¾Ý¿ ......
procedure Tform1.Button5Click(Sender: TObject);
var
p:pointer;
FrfStr:string;
begin
inherited;
Screen.Cursor:=MYCURSORWAITHAND;
with cdsPrint do
begin
Active:=false;
//Õâ¸öSQLÓÃÓÚ½«remarkÖеļǼºÏ²¢µ½Ò»Æ ......
Êý¾Ý¿âÊÂÎñÊÇÆäËûÊÂÎñÄ£Ð͵Ļù´¡£¬µ±Ò»¸öÊÂÎñ´´½¨Ê±²»Í¬Êý¾Ý¿âϵͳ¶¼ÓÐ×Ô¼ºµÄ¹æ
Ôò¡£SQL Server ĬÈÏÔÚ×Ô¶¯Ìá½»µÄģʽϹ¤×÷£¬Ã¿¸öÓï¾äÖ´ÐÐÍêºó¶¼»áÁ¢¼´Ìá½»£»Óë´Ë¶ÔÕÕ
µÄÊÇ Oracle ÐèÒªÄã°üº¬Ò»¸öÌá½»Óï¾ä¡£µ«Êǵ±Ò»¸öÓï¾äͨ¹ý OLE DB Ö´ÐÐʱ£¬ËüÖ´ÐÐÍêºó
Ò»¸öÌá½»¶¯×÷»á±»¸½¼ÓÉÏÈ¥¡£ÀýÈ磺
DECLARE  ......