本帖最后由 huang_w 于 2010-03-24 21:45:28 编辑

解决方案 »

  1.   

    应该是按ID分组的对吧,那么请看下面的答案。select a.id,a.begin_month||' 到 '||b.end_month as months,b.end_seq as months_num
      from (select distinct t1.id,
                            min(date_1) over(partition by id) as begin_month,
                            1 as begin_seq
              from (select t.*,
                           rank() over(partition by id order by date_1) as seq
                      from c t
                     where t.number_1 > 10) t1) a,
           
           (select distinct t1.id,
                            max(date_1) over(partition by id) as end_month,
                            max(seq) over(partition by id) as end_seq
              from (select t.*,
                           rank() over(partition by id order by date_1) as seq
                      from c t
                     where t.number_1 > 10) t1) b where a.id = b.id
       and b.end_seq >= 3
       and b.end_seq <= 5
       and months_between(to_date(b.end_month, 'yyyymm'),
                          to_date(a.begin_month, 'yyyymm')) =
           b.end_seq - a.begin_seq;
    至于月份的显示格式,如果一定要按LZ你的格式输出,你自己调整下咯。
      

  2.   

    date和number类型的字段改成了date_1,number_1