如何插入一个新行并根据其前一行的值增加一列?
How to insert a new row and increase a column based on its previous row's value?
Table 名称:可订购
ID (PK) || ORDER_ID || ITEMNAME || QTY
=======================================
1 || 1 || apple || 2
2 || 1 || orange || 5
3 || 2 || pear || 1
4 || 2 || grapes || 1
5 || 2 || melon || 1
如何根据 SQL 中 ORDER_ID 的前一个数字插入新行?
所以我会得到这个:
ID (PK) || ORDER_ID || ITEMNAME || QTY
=======================================
1 || 1 || apple || 2
2 || 1 || orange || 5
3 || 2 || pear || 1
4 || 2 || grapes || 4
5 || 2 || melon || 2
6 || 3 || mango || 3
目前我的查询字符串是:
insert into ORDERTABLE(ORDER_ID,ITEMNAME,QTY) values (LAST()+1, 'mango',3)
只得到这个错误:
wrong number of arguments used with function in query expression
INSERT INTO ORDERTABLE (ORDER_ID, ITEMNAME, QTY) SELECT MAX(ORDER_ID)+1, 'mango', '3' FROM ORDERTABLE;
Table 名称:可订购
ID (PK) || ORDER_ID || ITEMNAME || QTY
=======================================
1 || 1 || apple || 2
2 || 1 || orange || 5
3 || 2 || pear || 1
4 || 2 || grapes || 1
5 || 2 || melon || 1
如何根据 SQL 中 ORDER_ID 的前一个数字插入新行?
所以我会得到这个:
ID (PK) || ORDER_ID || ITEMNAME || QTY
=======================================
1 || 1 || apple || 2
2 || 1 || orange || 5
3 || 2 || pear || 1
4 || 2 || grapes || 4
5 || 2 || melon || 2
6 || 3 || mango || 3
目前我的查询字符串是:
insert into ORDERTABLE(ORDER_ID,ITEMNAME,QTY) values (LAST()+1, 'mango',3)
只得到这个错误:
wrong number of arguments used with function in query expression
INSERT INTO ORDERTABLE (ORDER_ID, ITEMNAME, QTY) SELECT MAX(ORDER_ID)+1, 'mango', '3' FROM ORDERTABLE;