20、列,该类别的层数可以写一个自定义函数来计算。该函数如下:CREATE FUNCTION dbo.CountLayer( @type_id int)RETURNS intASbegin declare @result int set @result=0 declare @lft int declare @rgt int if exists (select 1 from tree where type_id=@type_id) begin sel
21、ect @lft=lft,@rgt=rgt from tree where type_id=@type_id select @result = count(*) from tree where lft <= @lft and rgt >= @rgt end return @resultendGO然后,我们建立如下视图:CREATE VIEW dbo.TreeViewASSELECT type_