sqlµÝ¹é²éѯ
ÔÚ¹¤×÷ÖÐÓöµ½Ò»¸öÎÊÌâ,ÊÇÐèÒªsqlµÝ¹é²éѯµÄ.²»¶®,ÓÚÊǵ½csdnÉÏÈ¥ÎÊ,ÄÇÀïµÄЧÂÊÕæÊǷdz£¸ß,ÎÒÒÔǰҲûÔÚÉÏÃæÎʹýÎÊÌâ.
ÎÊÌâÃèÊö:
ÎÒÓÐÒ»¸ö±í½á¹¹ÈçÏÂ:
id upperid
1 2
3 2
4 1
5 3
¾ßÌå²ã´Î²»ÖªµÀ,ÎÒÏëÓõݹésqlÓï¾ä°ÑËùÓÐÊôÓÚij¸öupperidµÄÊý¾Ý,°üÀ¨ËüµÄ×ÓÊ÷,¶¼¶Á³öÈ¥£¬ÇëÎÊÓ¦¸Ã×ÓÔõôд?
±ÈÈç˵ upperid =2
ÄÇôÏÈÕÒµ½1,3,È»ºóÔÙÓÉ1,3ÕÒµ½4,5
ʹÓÃsqlÓï¾äʵÏÖ
ÓÐÁ½Î»ÅóÓѶ¼¸øÁ˻ظ´:
fa_ge(鶴嘯¾ÅÌì)
Create table t(id int,upperid int)
insert into t
select 1, 2
union all select 3, 2
union all select 4, 1
union all select 5, 3
select * from t
create function aa(@upperid int)
returns @t table (id int,upperid int,level int)
as
begin
declare @i int
set @i=1
insert into @t
select *,@i from t where upperid=@upperid
while @@rowcount>0
begin
set @i=@i+1
insert into @t
select a.*,@i from t a left join @t b on a.upperid=b.id
where b.level=@i-1
end
return
end
select * from dbo.aa(1)
id upperid level
----------- ----------- -----------
4 1 1
£¨ËùÓ°ÏìµÄÐÐÊýΪ 1 ÐУ©
select * from dbo.aa(2)
id upperid level
----------- ----------- -----------
1 2 1
3 2 1
4 1 &nbs
Ïà¹ØÎĵµ£º
SQL Server 2008 R2µÄÊ®´ó±ä»¯£¨ÉÏ£©£¬SQL Server 2008 R2µÄÊ®´ó±ä»¯£¨Ï£© ÕâÊ®´óÌØÐÔÖÐÎұȽϸÐÐËȤµÄÊÇStreamInsight£ºÍ¨¹ýSQL Server 2008 R2еÄStreamInsight×é¼þ£¬Microsoft½øÈëÁ˸´ÔÓʼþ´¦Àí(Complex Event Processing£¬CEP)¾ºÕù£¬ÆäÖÐÏà¹ØµÄ¹©Ó¦ÉÌ»¹ÓÐOracle¡¢IBMºÍStreamBase¡£
SQL Server 2008 R2ÒýÈëStreamIn ......
½ñÌìÔÚÓÃUNION½øÐн«Á½¸ö²éѯ½áºÏʱ£¬·¢ÏÖ¼ÓÁËtextÀàÐ͵Ä×ֶνøÈ¥¾Í±¨´íÁË£¬´íÎóÐÅÏ¢ÈçÏ£º
²»ÄÜÒÔ DISTINCT ·½Ê½Ñ¡Ôñ text¡¢ntext »ò image Êý¾ÝÀàÐÍ¡£
¾¹ý·ÔÄ×ÊÁϺó²ÅÖªµÀ£¬ÔÒòÔÚÓÚÈç´Ë²Ù×÷ ÎÞ·¨¶ÔtextÀàÐÍÅжÏÊÇ·ñÖظ´£¬ËùÒÔÒªÔÚUNIONºó¼Ó¸öALL¹Ø¼ü×Ö£¬ÈçÏ£º
select top ......
¡¡²Ù×÷·ûÓÅ»¯
¡¡¡¡IN ²Ù×÷·û
¡¡¡¡ÓÃINд³öÀ´µÄSQLµÄÓŵãÊDZȽÏÈÝÒ×д¼°ÇåÎúÒ׶®£¬Õâ±È½ÏÊʺÏÏÖ´úÈí¼þ¿ª·¢µÄ·ç¸ñ¡£
¡¡¡¡µ«ÊÇÓÃINµÄSQLÐÔÄÜ×ÜÊDZȽϵ͵ģ¬´ÓORACLEÖ´ÐеIJ½ÖèÀ´·ÖÎöÓÃINµÄSQLÓë²»ÓÃINµÄSQLÓÐÒÔÏÂÇø±ð£º
¡¡¡¡ORACLEÊÔͼ½«Æäת»»³É¶à¸ö±íµÄÁ¬½Ó£¬Èç¹ûת»»²»³É¹¦ÔòÏÈÖ´ÐÐINÀïÃæµÄ×Ó²éѯ£¬ÔÙ²éѯÍâ²ãµÄ±í¼Ç¼£ ......
Ëùν¶à·þÎñÆ÷¹ÜÀí (Multiserver Administration)¾ÍÊÇSQL Server 2008 R2ÌṩµÄ×Ô¶¯¹ÜÀí¶à¸ö SQL Server ʵÀý¹ý³ÌµÄ¹¦ÄÜ¡£ÔÚ¶à·þÎñÆ÷¹ÜÀíÖУ¬Á¬½Óµ½Ö÷·þÎñÆ÷²¢´ÓÆä½ÓÊÕ×÷ÒµµÄ·þÎñÆ÷±»³Æ֮ΪĿ±ê·þÎñÆ÷¡£SQL Server 2008 R2ÍƳöÁ˹ÜÀíSQL·þÎñÆ÷Êý¾Ý¿âÒýÇæµÄ¶à¸öʵÀýµÄSQL·þÎñÆ÷¹¤¾ß£¬Ê¹ÓÃÕâЩ¹¤¾ß¿ÉÒÔͨ¹ýÖÐÑë·þÎñÆ÷¶Ô¶à¸öSQL ......
½ñÌìÔÚÒ»¸öVPSÉÏ°²×°sql2005£¬°²×°ºÃºó±¾µØÒ»Ö±Á¬½Ó²»ÉÏ
¼ò½é
ÔÚ³¢ÊÔ´ÓÔ¶³Ì¼ÆËã»úÁ¬½Óµ½ Microsoft SQL Server 2005 ʵÀýʱ£¬¿ÉÄÜ»á½ÓÊÕµ½´íÎóÏûÏ¢¡£ÔÚʹÓÃÈκγÌÐòÁ¬½Óµ½ SQL Server ʱ¶¼¿ÉÄܻᷢÉú´ËÎÊÌâ¡£ÀýÈ磬ÔÚʹÓà SQLCMD ʵÓù¤¾ßÁ¬½Óµ½ SQL Server ʱÊÕµ½ÒÔÏ´íÎóÏûÏ¢£º
Sqlcmd:´íÎó:Microsoft SQL Native Cli ......