DB2 Update语句

时间:2013-10-11 07:52:28

标签: 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不确定。有人可以帮我这个吗?

2 个答案:

答案 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