0

我对 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。谁能帮我解决这个问题?

4

2 回答 2

0

这个选择也适用于 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; 

您想如何将其转换为更新语句?

于 2013-10-16T15:02:59.877 回答
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
于 2018-07-19T21:17:51.173 回答