本文介绍了如何更新序列列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

实际表
EMPID SALARY序列
1 2000 NULL
1 2344空
1 2345空
2 4444空
2 4434空
2 3434空
3 2344空
3 3456 NULL

我需要更新Sequence列的结果应该如下
EMPID SALARY序列
1 2000 1
1 2344 2
1 2345 3
2 4444 1
2 4434 2
2 3434 3
3 2344 1
3 3456 2

HI All,

Actual Table
EMPIDSALARYSequence
12000NULL
12344NULL
12345NULL
24444NULL
24434NULL
23434NULL
32344NULL
33456NULL

I need to update Sequence column result should be as follows
EMPIDSALARYSequence
120001
123442
123453
244441
244342
234343
323441
334562

推荐答案

select t.rowno, t.EmpID, t.Salary into #temp from
(
   select row_number() over(partition by EMPID order by EmpID) as rowno, empID, Salary
   from ActualTable
) as t

-- to see the result you can do
select * from #temp

-- update your data
update ActualTable
 set Sequence = t.rowno
from #temp as t
inner join ActualTable as a on a.empID = t.empID and a.Salary = t.Salary

drop table #temp


这篇关于如何更新序列列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:23