sql 人员按照部门进行排序,急等 》》》》》》》》
人员表workuser
ID UserID DeptID
对应部门表
dept
ID Name ParentID
1 总部 0
2 开发部 1
3 市场部 1
4 事业部 0
5 客服部 4
希望能够实现 按照部门 进行 人员排序
其中 部门 分为一级部门和二级部门
先循环一级部门人员,再循环二级部门人员
哪位可以帮帮我 ,很急.........
哪位可以帮帮我 》》》》》》》》》》》》
--------------------编程问答-------------------- 怎么没人说话呢 。》》 --------------------编程问答-------------------- --------------------编程问答--------------------
with rept(ID,Name,ParentID)
as(
select 1,'总部',0 union all
select 2,'开发部',1 union all
select 3,'市场部',1 union all
select 4,'事业部',0 union all
select 5,'客服部',4),
tb as(
select * from rept where parentid=0 union all
select rept1.* from rept rept1,tb tb1 where tb1.id=rept1.parentid
),rpt as(
select row=row_number()over(order by getdate()),* from tb)
select w1.* from workuser w1,rpt r1 where r1.id=w1.id order by r1.row
--------------------编程问答--------------------
谢谢回复
补充:.NET技术 , ASP.NET