所以目前我正在使用这个查询
INSERT INTO tb_first_wallet_transactions
(
vendor_id,
amount,
transaction_type,
status,
checksumhash
)
SELECT
vendor_id,
amount,
transaction_type,
status,
checksumhash
FROM
tb_second_wallet_transactions
WHERE id = 1
还有一个列名type
在tb_first_wallet_transaction
可以是 0 或 1,我也需要添加,但问题是第二个表中没有这样的列。
一个解决方案是我运行一个查询,该查询在特定时间戳(即上述查询的插入时间)后更改 do type == 1
但我想在一个查询中完成所有插入。这可能吗?
最佳答案
只需在列列表中添加类型
,并在SELECT
中添加默认值即可:
INSERT INTO tb_first_wallet_transactions (vendor_id, amount, transaction_type, status, checksumhash, type)
SELECT
vendor_id,
amount,
transaction_type,
status,
checksumhash,
0 -- Choose your default value
FROM tb_second_wallet_transactions
WHERE
id = 1
关于mysql - 我想将第一个 SQL 表中的数据插入到第二个 SQL 表中,并且第二个 SQL 表中不存在额外的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37936152/