sqlserver中实现递归查询

    技术2022-05-11  68

    create function iterate_fun(@id int) returns @t table(id int,parentid int,level int) begin declare @i int set @i=1 insert @t select id,parent_id,@i from b_project_land where parent_id=@id while @@rowcount<>0 begin set @i=@i+1 insert @t select pl.id,pl.parent_id,@i from b_project_land pl,@t b where b.id=pl.parent_id and b.level=@i-1 end return end   

    最新回复(0)