WITH CTE AS
(
SELECT *, ROW_NUMBER() OVER (PARTITION BY ID, SEQ_NO ORDER BY SEQ_NO) rn
FROM table_name
)
SELECT ID, SEQ_NO,
CASE
WHEN rn>1 THEN
CONCAT(CHAR(rn+63), CHAR(rn+63), SEQ_NO)
ELSE SEQ_NO
END AS new_seq
FROM CTE
WHERE rn <= 27
ORDER BY ID, new_seq
如果要更新SEQ_NO列,请执行以下操作:
WITH CTE AS
(
SELECT *, ROW_NUMBER() OVER (PARTITION BY ID, SEQ_NO ORDER BY SEQ_NO) rn
FROM table_name
)
UPDATE CTE SET SEQ_NO = CONCAT(CHAR(rn+63), CHAR(rn+63), SEQ_NO)
WHERE rn > 1 AND rn <= 27
1条答案
按热度按时间mgdq6dx11#
请尝试使用
ROW_NUMBER
函数执行以下操作:如果只想选择SEQ_NO作为新列,请执行以下操作:
如果要更新SEQ_NO列,请执行以下操作:
请参见demo,其中一组数据的seq(01 - 10)重复三次。