我现在要实现以下业务,将A表中的时间段用B表中的时间段进行分割后,获得多段,
取数据表A中不在数据表B中的时间段,时间段可能不是整月,也就是以B中开始日期的前一天为A中上一段的截止时间,其中A和B中的end_date有可能为空,A.B中的时间段均可能不连续
例如以下数据
数据表A
type1 begin_date end_date
1 20130901 null
2 20130501 20131231
2 20140201 20140531
数据表B
type1 begin_date end_date
1 20131001 20131031
2 20130601 20130701
2 20130901 20130930
想要的结果
type1 begin_date end_date
1 20130901 20130930
1 20131031 null
2 20130501 20130531
2 20130702 20130831
2 20131001 20131231
2 20140201 20140531
oracle sql 分割时间段
取数据表A中不在数据表B中的时间段,时间段可能不是整月,也就是以B中开始日期的前一天为A中上一段的截止时间,其中A和B中的end_date有可能为空,A.B中的时间段均可能不连续
例如以下数据
数据表A
type1 begin_date end_date
1 20130901 null
2 20130501 20131231
2 20140201 20140531
数据表B
type1 begin_date end_date
1 20131001 20131031
2 20130601 20130701
2 20130901 20130930
想要的结果
type1 begin_date end_date
1 20130901 20130930
1 20131031 null
2 20130501 20130531
2 20130702 20130831
2 20131001 20131231
2 20140201 20140531
oracle sql 分割时间段
例如 A 20130901-null B 20131101-20131231
A中刨除B后的结果为 20130901-20131031 20140101-null