各位大哥,小弟现在遇到个问题,困惑了1天多了,有经验的大哥给点指导,多谢多谢单表查询更新数据id date       col1 col2
01 2000-12-12 1a   1b
01 2002-12-12 1b   1c
01 2010-2-1   1a   1b
02 2010-1-5   2a   2b
02 2030-4-1   2a   2b
03 2000-12-12 3a   1b
03 2020-6-9   3a   1b
03 2033-2-10  3a   3b有id date 联合主键
现在要查询出id下个日期更新过数据的那些行。

解决方案 »

  1.   

    就是同一个id,但是不同的date,如果后面列的数据又不同就列出来
      

  2.   

    如果 id 一样 date 不一样   后面数据一样 要不要列出来
      

  3.   

    id 和 date 基本可以当做联合主键,当然要列出来。
      

  4.   


    不好意思,说错了,id一样,date不一样,后面的数据一样的话,就是没有更新过,不用列出来的。
      

  5.   


    create table Tab1 as
    (
     select '01' a,'2000-12-12' b,'1a' c,'1b' d from dual union
     select '01','2000-12-12','1b','1c' from dual union
     select '01','2000-2-1','1a','1b' from dual union
     select '02','2000-1-5','2b','2b' from dual union
     select '02','2000-4-1','2a','2b' from dual union
     select '03','2000-12-12','3a','1b' from dual union
     select '03','2000-6-9','3a','1b' from dual union
     select '03','2000-2-10','3a','3b' from dual   
    );
     
    select distinct t1.* from tab1 t1,tab1 t2
    where t1.b <> t2.b and t1.a=t2.a and (t1.c <> t2.c or t1.d <> t2.d)
    order by t1.a ,t1.b;
      

  6.   


    抱歉,不能用distinct,这样不是逐条比较
    需求是和下个date比较,如果下下条数据又被改了回来,依然要拉出来
      

  7.   

    select case lag(t.date)!=lead(t.date) then coll from table t where t.id=1
      

  8.   

    谢谢楼上的兄弟,我的sql不能用case之类的,就是简单的自连接查询,问题我已自己解决,多谢大家帮忙。