亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

存儲(chǔ)過(guò)程里的遞歸 實(shí)現(xiàn)方法

 更新時(shí)間:2006年12月28日 00:00:00   作者:  
一個(gè)二叉樹(shù)的遞歸,找出左邊最下面的一個(gè)點(diǎn) 
id 自動(dòng)編號(hào) 
pid 父ID 
id_path 節(jié)點(diǎn)路徑 
flg 位置,0左邊,1右邊 
ALTER      PROCEDURE [dbo].[get_class] 

復(fù)制代碼 代碼如下:
@class int, 
@return int output 
AS 

SELECT  @return=isnull(( select top 1 id  from class where pid=@class and flg=0 ),-2) 

if @return>-1 
    begin 
    exec get_class @return,@return output--這里為什么要用@return,你要最后得到這個(gè)值,必須把它傳進(jìn)去 

    end 

else 
    begin 
    SELECT @return=@class 
    end 
GO 
 
其實(shí)只需一個(gè)查詢(xún)語(yǔ)句就能找出最下面的ID 
節(jié)點(diǎn)路徑包函1,并且父節(jié)點(diǎn)位置都是左邊,取出最大一個(gè) 
select top 1 * from class a where id_path like '%1,%' and flg=0 and (select flg from class where id=a.pid)=0 order by id desc

相關(guān)文章

最新評(píng)論