我在这里遵循的过程是,将数据插入新表时,如果在中断表a中有条目,则更新开始和结束日期
INSERT INTO NewTable
SELECT NVL(i2.endDate+1,e.startDate) AS startDate
,NVL(i1.startDate-1,e.endDate) AS endDate
,e.year
,e.codeMission
,e.employeNumber
,e.type
FROM Employee e
LEFT JOIN Interruption i1 ON e.employeNumber=i1.employeNumber AND YEAR(e.startDate)=YEAR(i1.startDate)
LEFT JOIN Interruption i2 ON e.employeNumber=i1.employeNumber AND YEAR(e.endDate)=YEAR(i2.endDate)
现在我们已经将employee表中的数据转换为与interruption表匹配的数据,所以现在我们移动interruption表中的数据
INSERT INTO NewTable
SELECT startDate
,endDate
,year
,codeMission
,employeNumber
,type
FROM Interruption