user_his
userid |
username |
phone |
start_date |
end_date |
1001 |
zhangsan |
13066666666 |
2020-09-01 |
9999-12-31 |
1002 |
lisi |
13055555555 |
2020-09-01 |
9999-12-31 |
1003 |
wangwu |
13077777777 |
2020-09-01 |
9999-12-31 |
user_update
userid |
username |
phone |
1001 |
zhangsan |
13088888888 |
1002 |
lisi |
13044444444 |
user_his
userid |
username |
phone |
start_date |
end_date |
1001 |
zhangsan |
13066666666 |
2020-09-01 |
2020-09-13 |
1002 |
lisi |
13055555555 |
2020-09-01 |
2020-09-13 |
1003 |
wangwu |
13077777777 |
2020-09-01 |
9999-12-31 |
1001 |
zhangsan |
13088888888 |
2020-09-14 |
9999-12-31 |
1002 |
lisi |
13044444444 |
2020-09-14 |
9999-12-31 |
1.将更新表所有数据插入到user_his 中,并将起始日期设置为今天,截至日期为9999-12-31。
2.用历史表left join更新表,如果能够join上,那么将历史表中截至日期改为昨天,使用overwrite覆盖掉。
实操
<