1

需要在 3 个新行中复制 1 行,并且在每个新行中增加序列号 +1

insert into t1 (column1,column2,column3,sequencecolumn)
(  **row1
select *from t1 (column1,'101',column3,sequencecolumn)
(select max (sequencecolumn)+1 where column1 ='abc')
where column1 = 'abc'
)  
(   ***row2
select *from t1 (column1,'102',column3,sequencecolumn)
(select max (sequencecolumn)+1 where column1 ='abc')
where column1 = 'abc'
)
(  ***row3
select *from t1 (column1,'103',column3,sequencecolumn)
(select max (sequencecolumn)+1 where column1 ='abc')
where column1 = 'abc'
)
4

1 回答 1

1

我可能会尝试这样的事情(如果我有一个方便的 DB2 安装):

INSERT INTO t1 (
  column1,
  column2,
  column3,
  sequencecolumn
)
SELECT
  t.column1,
  v.column2,
  t.column3,
  MAX(t.sequencecolumn) + v.rn
FROM t1 t
CROSS JOIN (VALUES (1, '101'), (2, '102'), (3, '103')) v (rn, column2)
GROUP BY
  t.column1,
  t.column3,
  v.column2,
  v.rn
WHERE t.column1 = 'abc'
;
于 2012-10-07T20:58:48.157 回答