表名:ORDERTABLE
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
答案 0 :(得分:1)
INSERT INTO ORDERTABLE(ORDER_ID,ITEMNAME,QTY)SELECT MAX(ORDER_ID)+1,' mango',' 3'来自ORDERTABLE;