技术饭
mysql替换字段值为另外一个表的字段值
mysql替换字段值为另外一个表的字段值,需求是:替换充值订单中的时间为另外一张表的时间字段;解决思路:使用 INNER JOIN 查询的方式查出来数据之后再进行update更新。
#充值订单(流水)
SELECT
a.create_time,
b.create_time AS b_create_time,
a.change_type,
a.order_id,
a.order_sn,
b.order_sn AS b_order_sn,
a.pay_trade_no,
b.pay_trade_no AS b_pay_trade_no
FROM
`aikehou_brand_fundlist_log` a
INNER JOIN
(SELECT
pay_trade_no,
order_sn,
create_time
FROM
`brand_finance`) b
ON a.pay_trade_no = b.pay_trade_no WHERE change_type='recharge' ORDER BY order_id ASC;
#充值订单
SELECT
a.pay_time,
b.create_time AS b_create_time,
a.id,
a.order_sn,
b.order_sn AS b_order_sn,
a.pay_trade_no,
b.pay_trade_no AS b_pay_trade_no
FROM
`aikehou_brand_recharge` a
INNER JOIN
(SELECT
pay_trade_no,
order_sn,
create_time
FROM
`brand_finance`) b
ON a.pay_trade_no = b.pay_trade_no ORDER BY id ASC;
#更新充值订单(流水)
UPDATE
`aikehou_brand_fundlist_log` a
INNER JOIN
(SELECT
pay_trade_no,
order_sn,
create_time
FROM
`brand_finance`) b
ON a.pay_trade_no = b.pay_trade_no SET a.`create_time` = b.create_time WHERE change_type='recharge';
#更新充值订单
UPDATE
`aikehou_brand_recharge` a
INNER JOIN
(SELECT
pay_trade_no,
order_sn,
create_time
FROM
`brand_finance`) b
ON a.pay_trade_no = b.pay_trade_no SET a.`pay_time` = b.create_time;
其中brand_finance表结构:
文明上网理性发言!