我手头有一个数据库,以月为单位连续记录数据,从开始使用直到使用寿命终了都要记录在案,
现在我想要统计中间是否有间断点,比如说上一个记录是200501,下一个就成了200503,可否将这样的
的间断点一次性选择出来。
库结构(cpmc,ny,...),主键(cpmc,ny)

解决方案 »

  1.   

    你的cpmc ,ny都分别指代什么???
    是月和年吗...
    还是月年写在一个字段上呀
    请指明.....
      

  2.   

    网上其实有好多关于连续性检查的方法,告诉你一种简单的办法:create table tmp(ny varchar2(6),cnt number(10));
    insert into tmp(ny)values('200501');
    ......
    insert into tmp(ny)values('200512');
    commit;
    update tmp a
    set a.cnt=(
    select count(*)
    from 你的表 b
    where b.ny=a.ny
    );
    commit;
    select * from tmp where cnt=0;
      

  3.   

    select * from (
    select add_months(to_date('200501', 'yyyymm'), rownum-1) col1 from dual
    connect by rownum<=12) t1
    where not exists (select 1 from table_name t2 where t1.col1=trunc(日期字段, 'mm'))select add_months(to_date('200501', 'yyyymm'), rownum-1) col1 from dual
    connect by rownum<=12
    构造连续月份,起始时间是200501, rownum<=12 为12个月
      

  4.   

    不好意思,看来是我没说清楚
    我现在要做的是以cpmc为分组,把每一种cpmc中的时间连续性做一检查