emp_his表存放历史数据,emp_inc表存放有变化,或者新增的数据,如果要一个最新的全量数据,SQL如何写

图片说明

select * from 增量表 union All (select * from 原始表 where emp_id not in (select emp_id from 增量表));

全量= 增量 + (原始-增量中更新的)

应该没问题了,你试试,做题应该没什么问题,要是真实项目这样可能性能不高。等一个大神出手


select
        *
from 增量表
union All
(select
        *
from 原始表
where emp_id not in (select emp_id from 增量表))
union ALL 
(SELECT 
        *
FROM 增量表 LEFT JOIN 原始表 ON 增量表.emp_id = 原始表.emp_id
);