[英]I want to insert data from first SQL table into second one also with an extra column not present in the second one
So currently I am using this query 所以目前我正在使用此查询
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
There is also a column name type
in tb_first_wallet_transaction
that can be 0 or 1 , that I also needs to add, but the problem is that there is no such column in the second table. 在
tb_first_wallet_transaction
中还有一个列名type
,可以是0或1 ,我也需要添加,但是问题是第二个表中没有这样的列。
One solution is that I run a query which changes does type == 1 after a certain time stamp (ie of the insertion time of above query) 一种解决方案是我运行一个查询,该查询在一定的时间戳(即上述查询的插入时间)之后更改类型== 1
But I want to do all the insertion in one single query. 但是我想在一个查询中完成所有插入操作。 Is that possible ??
那可能吗 ??
Just add the type
in the column list and add a default value in your SELECT
: 只需在列列表中添加
type
,然后在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.