我是DB2的新手。我有一个选择查询,我需要转换为更新语句。查询是这样的:
SELECT GUID,seq original_seq_no, ROW_NUMBER()
OVER ( PARTITION BY GUID ORDER BY seq) AS new_seq_no
FROM CHK_SEQ;
此选择查询适用于MSSQl和Oracle,但对DB2不确定。有人可以帮我这个吗?
答案 0 :(得分:0)
此选择也适用于DB2。即。
WITH CHK_SEQ (GUID, seq, original_seq_no) AS (VALUES
('guid1', 100, 1001),
('guid2', 200, 1002),
('guid3', 300, 1003)
)
SELECT GUID,seq, original_seq_no, ROW_NUMBER()
OVER ( PARTITION BY GUID ORDER BY seq) AS new_seq_no
FROM CHK_SEQ;
您希望如何将其转换为更新语句?
答案 1 :(得分:0)
尝试这个简单的表格
UPDATE (
SELECT GUID,seq, ROW_NUMBER()
OVER ( PARTITION BY GUID ORDER BY seq) AS new_seq_no
FROM CHK_SEQ
) SET seq = new_seq_no