因此,我有一个带有数字字段作为键的表。随着记录的添加,该字段每增加一个。然后有时会删除记录,留下与1,2,5,6,8,9,13等类似的序列。新记录总是添加为比序列中前一个最大数字高一个。我处于一种情况,需要通过追加查询插入大约9000条新记录,但是追加始终将相同的第二高的数字应用于所有新记录。下面是我目前所能得到的,标记为“ Expr1”的位是一个例证,尽我所能来做。
INSERT INTO ALTSTRAT ( ALT_STRAT_ID, FIELD1, FIELD2, FIELD3, FIELD4, FIELD5 )
SELECT Max(ALT_STRAT_ID)+1 AS Expr1, "PROM" AS Expr2,
ITEM.ITM_NUM, "@" AS Expr3, ITEM.MASTER_STRAT, 0 AS Expr4
FROM ITEM
GROUP BY "PROM", ITEM.ITM_NUM, "@", ITEM.MASTER_STRAT, 0;
我们非常感谢您的帮助,我没有太多可扯的头发了。谢谢!
答案 0 :(得分:0)
似乎ALT_STRAT_ID
实际上 是一个自动编号。因此,只需在插入时忽略它-它会自动出现-无需按常量值分组:
INSERT INTO ALTSTRAT
( FIELD1, FIELD2, FIELD3, FIELD4, FIELD5 )
SELECT
"PROM" AS Expr2, ITEM.ITM_NUM, "@" AS Expr3, ITEM.MASTER_STRAT, 0 AS Expr4
FROM
ITEM
GROUP BY
ITEM.ITM_NUM, ITEM.MASTER_STRAT;