我对 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。谁能帮我解决这个问题?
我对 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。谁能帮我解决这个问题?
这个选择也适用于 DB2。IE
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;
您想如何将其转换为更新语句?
试试这个简单的表格
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