什么意思?你要先判断这字段先为Y后变成N?SQL语句只能判断数据库当前的数值,不能识别一个过程的变化吧,楼主如果想要看到这种变化最好建2个字段来识别!

解决方案 »

  1.   

    select a,b from t 
    where d>trunc(sysdate) group by a,b having count(*)>1;
      

  2.   

    楼主,是不是找出今天,状态先为Y后为N的用户记录?这样行不行:
    select Y.a,Y.b,Y.max_d,N.min_d
    from 
         (select a,b,max(d) max_d 
          from t 
          where d>trunc(sysdate) 
          and f='Y' 
          group by a,b) Y,      (select a,b,min(d) min_d 
          from t 
          where d>trunc(sysdate) 
          and f='N' 
          group by a,b) Nwhere Y.max_d<=N.min_d
    and Y.a=N.a 
    and Y.b=N.b;
      

  3.   

    楼主,是不是找出今天,状态先为Y后为N的用户记录?这样行不行:
    select Y.a,Y.b,Y.max_d,N.min_d
    from 
         (select a,b,max(d) max_d 
          from t 
          where d>trunc(sysdate) 
          and f='Y' 
          group by a,b) Y,      (select a,b,min(d) min_d 
          from t 
          where d>trunc(sysdate) 
          and f='N' 
          group by a,b) Nwhere Y.max_d<=N.min_d
    and Y.a=N.a 
    and Y.b=N.b;
      

  4.   

    select a,b from t t1
    where f ='Y'
      and trunc(d) = trunc(sysdate)
      and exists(select 1 from t t2 where t2.a=t1.a and t2.b=t1.b and t2.d>t1.d and t2.f='N')
      

  5.   

    select a,b from t t1
    where f ='Y'
      and trunc(d) = trunc(sysdate)
      and exists(select 1 from t t2 where t2.a=t1.a and t2.b=t1.b and t2.d>t1.d and t2.f='N' and trunc(t2.d) = trunc(sysdate))
      

  6.   

    select WW.USERNAME from    
       (select a||b  AS USERNAME from t 
       where t=to_char(sysdate,'yyyymmdd')
       and f='N' ) WW,
       (select a||b AS USERNAME from t 
       where t=to_char(sysdate,'yyyymmdd')
       and f='Y' ) XX
    WHERE WW.USERNAME=XX.USERNAME
      

  7.   

    广丽的思路对!觉得要做些修改,
    如果今天的记录有100条,前99条一直是Y,最后一条是N,那么这么查出来的就有99条,而实际应该是查出有Y-->N的记录。应该是99+100那两条记录,对不?