mysql 如何移动列名或给定值与表定义不匹配的最近数据?

bqf10yzr  于 2023-02-18  发布在  Mysql
关注(0)|答案(1)|浏览(141)

如何移动列名或给定值与定义表不匹配的最新数据。例如,我有一个SalesInvoice表,并希望将其移动到PurchaseInvoice表,而该表实际上与该表具有相同的列名,但结构不同(例如SalesInvoice中的SalesInvoiceID在第2列,而SalesInvoiceID PurchaseInvoice在第6列)。我已经尝试到此处,但仍然出现错误

BEGIN TRAN
INSERT INTO PurchaseInvoice
SELECT \* FROM SalesInvoice
WHERE SalesInvoice.SalesInvoiceID = '016'
wh6knrhe

wh6knrhe1#

您可以通过按顺序提及您的列来做到这一点:

INSERT INTO pbx_intovoice.tag (column1, column2, column3, column4)
select column1, column2, column3, column4
FROM SalesInvoice 
WHERE SalesInvoice.SalesInvoiceID = '016'

如果列名与接收方表不同,您仍可以从接收方表插入数据:

INSERT INTO pbx_intovoice.tag (column1, column2, column3, column4)
select s.col1 as column1, s.col2 as column2, s.col3 as column3, s.col4 as column4
FROM SalesInvoice s
WHERE s.SalesInvoiceID = '016'

相关问题