[英]update column using ROW_NUMBER
I'm trying to update a column using ROW_NUMBER(), but just works sometimes, what's wrong?我正在尝试使用 ROW_NUMBER() 更新列,但有时会起作用,有什么问题? This is the instruction:
这是指令:
update temp1 set temp1.RowNumber = m.RowID
from
(
select ROW_NUMBER() OVER (ORDER BY t.id_pv) as 'RowID', id_pv
from temp1 t
) m
where temp1.id_pv = m.id_pv
Here are two columns of the table before and after update这是更新前后的两列表
If I run only:如果我只运行:
select ROW_NUMBER() OVER (ORDER BY t.id_pv) as 'RowID', id_pv from temp1 t
it works like a charm.它就像一个魅力。 Ideas?
想法?
If id_pv
is not unique, then the select won't produce stable results.如果
id_pv
不是唯一的,那么选择将不会产生稳定的结果。 You may need to add another column that is unique to the ORDER BY
clause to stabilize the sort.您可能需要添加
ORDER BY
子句独有的另一列以稳定排序。 That should produce repeatable results.这应该会产生可重复的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.