UPDATE SET a.id = (select) 关联多张表更新多条记录

UPDATE wallet_account_trade_record A
SET A.shop_id =(
SELECT
c.shop_id
FROM
mob_checkout_counter.payment_data_info B,mob_checkout_counter.checkout_record c
WHERE A.client_trade_sn=B.sn
and B.record_id = c.id

)
WHERE
EXISTS(
SELECT
1
FROM
mob_checkout_counter.payment_data_info B,mob_checkout_counter.checkout_record c
WHERE A.client_trade_sn=B.sn
and B.record_id = c.id
)

直接update一张表,下面set语句就更新哪个字段,从select中查询出要更新的值,select出多条记录,要加where限制条件,限制一条结果一条结果的更新

你可能感兴趣的:(数据库)