34,591
社区成员
发帖
与我相关
我的任务
分享
declare @t table(empid int,empname varchar(10),deptid int)
insert into @t select 1,'员工A',5
insert into @t select 2,'员工B',5
insert into @t select 3,'员工C',7
insert into @t select 4,'员工D',7
insert into @t select 5,'员工E',9
insert into @t select 6,'员工F',5
insert into @t select 7,'员工G',7
insert into @t select 8,'员工H',9
insert into @t select 9,'员工I',3
select px=(select count(1) from @t where deptid=a.deptid and empid<=a.empid),* from @t a
order by px,deptid