select identity(int,1,1)userid,* into #t from(
select 'name1'LoginName,0 FatherUserID
union all select 'name2', 1
union all select 'name3', 1
union all select 'name4', 2
union all select 'name5', 2
union all select 'name6', 4
union all select 'name7', 4
)a
;with temp_users as
(
select UserID,LoginName,FatherUserID,1 as levle from #t where UserID=1
union all
select A.UserID,A.LoginName,A.FatherUserID,B.levle+1 from #t A,temp_users B where A.FatherUserID=B.UserID
)
select count(userid) as count,[level] from temp_users group by [level]