现有3张表,2张同步表,一张本地表,现在需要将同步表中的数据更新到本地表中。mysql 因为不支持 全关联,所以只能使用左、右分别关联两张表的方式获取全量信息。
通过insert select from 的方式,合并表数据。
INSERT INTO cust_first_trade(
cust_id,
htsc_first_trade_dt,
zd_first_trade_dt
)SELECT
a.client_id,a.first_trade_date,b.trading_date
FROM
cust_sjzx.client_first_trade a
LEFT JOIN cust_sjzx.first_trade_date b ON a.client_id = b.client_id
union
SELECT
d.client_id,c.first_trade_date,d.trading_date
from cust_sjzx.client_first_trade c
RIGHT JOIN cust_sjzx.first_trade_date d ON c.client_id = d.client_id