我想将数据从一个表传输到另一个表,我还想在第二个表中添加一个额外的列。
INSERT INTO invoiceitem(invoiceno, barcode, itemname, quantity, unitprice, subamount)
VALUES
('$Succ2', SELECT barcode, resultname, quantity, resultprice, subamount)
FROM test;
答案 0 :(得分:0)
如果要使用查询的结果集插入,则语法为INSERT INTO ... SELECT
,即在这种情况下我们不使用VALUES
。可以向SELECT
语句添加文字值,例如试试这个:
INSERT INTO invoiceitem (invoiceno, barcode, itemname, quantity, unitprice, subamount)
SELECT '$Succ2', barcode, resultname, quantity, resultprice, subamount
FROM test;
答案 1 :(得分:0)
正确的语法是:
INSERT INTO invoiceitem(invoiceno,barcode,itemname,quantity,unitprice,subamount)
SELECT '$Succ2' ,barcode,resultname,quantity,resultprice,subamount FROM test;
答案 2 :(得分:0)
如果要将值从一个表插入另一个表,则无需在插入查询中使用VALUES。请参考INSERT TABLE TO ANOTHER TABLE
INSERT INTO invoiceitem (invoiceno, barcode, itemname, quantity, unitprice, subamount)
SELECT '$Succ2' barcode, resultname, quantity, resultprice, subamount
FROM test;