会员表:
id,name,pid,othermessage
查询某 id 直接推荐的会员:
select * from 会员表 where pid=@id
查询某 id 下级的所有会员:
;with cte as(
select * from 会员表 where pid=@id
union all
select b.* from cte a inner join 会员表 b on a.id=b.pid --补一个 b
)select * from cte
会员表:
id,name,pid,othermessage
查询某 id 直接推荐的会员:
select * from 会员表 where pid=@id
查询某 id 下级的所有会员:
;with cte as(
select * from 会员表 where pid=@id
union all
select b.* from cte a inner join 会员表 on a.id=b.pid
)select * from cte