我现在要实现以下业务,将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 分割时间段

解决方案 »

  1.   

    简单来说就是把A中的数据用B中的去截取,获得A中刨除B后的时间段,这样会不会好明白一些
    例如 A 20130901-null   B 20131101-20131231
    A中刨除B后的结果为  20130901-20131031   20140101-null
      

  2.   

    实现可能有点麻烦 看到需求后的初步思路 通过表A 中的type1的最大最小时间 来构造一个时间表 然后关联表B 过滤掉表B同个type1包涵的时间段然后将过滤后的时间段 来根据天数是否连续来分组 最后得出每个分组的最大最小时间 就是需要的结果 不知道还有没其他简单思路..