簡體   English   中英

我想將第一個SQL表中的數據插入第二個SQL表中,而第二個表中不存在額外的列

[英]I want to insert data from first SQL table into second one also with an extra column not present in the second one

所以目前我正在使用此查詢

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

tb_first_wallet_transaction中還有一個列名type ,可以是01 ,我也需要添加,但是問題是第二個表中沒有這樣的列。

一種解決方案是我運行一個查詢,該查詢在一定的時間戳(即上述查詢的插入時間)之后更改類型== 1

但是我想在一個查詢中完成所有插入操作。 那可能嗎 ??

只需在列列表中添加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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM