拉链表
select * from order_info_20210726;--快照, select * from ORDER_INFO_DZ ;--拉链表 --重跑 delete from order_info_dz where date_id='2020-09-13' --第一次加工初始化所有数据 insert into order_info_dz select a.order_id, a.order_status, a.create_time, a.update_time, substr(a.update_time,0,10), '9999-12-31', '2020-09-10' from order_info_20210726 a --抽取更新及当天新增数据 insert into order_info_dz select a.order_id, a.order_status, a.create_time, a.update_time, a.start_dt, --a.end_dt, --b.order_id , case when a.end_dt ='9999-12-31' and b.order_id is not null then a.date_id else a.end_dt end, '2020-09-11' from order_info_dz a left join order_info_20210726 b on a.order_id=b.order_id where a.date_id='2020-09-10' union all select a.order_id, a.order_status, a.create_time, a.update_time, substr(a.update_time,0,10), '9999-12-31', '2020-09-11' from order_info_20210726 a --查看当前所有有效记录 select * from order_info_dz b where b.end_dt='9999-12-31' and date_id='2020-09-11' --查看9月10日快照 select * from order_info_dz m where m.date_id = '2020-09-10' and m.start_dt <= '2020-09-10' and end_dt>='2020-09-10'; --查看9月11日快照 select * from order_info_dz m where m.date_id = '2020-09-11' and m.start_dt <= '2020-09-11' and end_dt>='2020-09-11';