sqlserver,sql根据部门id逐级获取上级部门信息,并存放到list中

with cte as
(
select dept_id,parent_dept,dept_name,dept_man, 0 as lvl from w_h_dept
where dept_id = 'T090102'
union all
select d.dept_id,d.parent_dept,d.dept_name,d.dept_man,lvl + 1 from cte c inner join w_h_dept d
on c.parent_dept= d.dept_id
)

select e.*,u.user_name from cte e LEFT JOIN x_userinfo u on e.dept_man=u.user_id

上一篇:URL化


下一篇:实验八 进程间通信