SQL> select * from testa;V1         V2                    T                        X          Y
---------- ---------- ---------- ---------- ----------  ------------
v1         v2                07-08-17 04:42:40           1          1
f          f                 07-08-17 04:42:41           1          1
jh         h                 07-08-17 04:42:42           1          2
jh         h                 07-08-17 04:42:43           1          2
g          h                 07-08-17 04:42:45           4          5
表结构如上,(x,Y)代表每一个点,t代表对点操作的时间, v1,v2是操作参数.请问怎样把所有最后操作的点查出来:想要的结果应如下图所示:
SQL> V1         V2                    T                        X          Y
---------- ---------- ---------- ---------- ----------  ------------
f          f                 07-08-17 04:42:41           1          1
jh         h                 07-08-17 04:42:43           1          2
g          h                 07-08-17 04:42:45           4          5

解决方案 »

  1.   

    Select * from testa A where not exists(
     Select v1 from testa where v1=A.v1 and v2=A.v2 and T>A.T )
      

  2.   


    SQL> Select * from testa A where not exists(
      2   Select v1 from testa where v1=A.v1 and v2=A.v2 and T>A.T );V1         V2                  T          X          Y
    ---------- ---------- ---------- ---------- ----------
    jh         h                   2          1          2
    g          h                   5          4          5
    f          f                   2          1          1
    v1         v2                  1          1          1以上是"WangZWang"给的语句执行结果,
    多了一条记录......
      

  3.   

    v1         v2                  1          1          1
    ------------------------------------------------------
    以上这条记录要去掉就是要的结果,如下:
    V1         V2                  T          X          Y
    ---------- ---------- ---------- ---------- ----------
    jh         h                   2          1          2
    g          h                   5          4          5
    f          f                   2          1          1
      

  4.   

    为什么要去掉? 这笔数据和其他没有规律?
    否则只有强制去掉 and V1<>'v1'  ??
      

  5.   

    因为我对于每一个点我只要最后一次操作,
    (1,1)这个点对应的最后一次操作是:
    f          f                   2          1          1
    --------------------------------------------------------
    而不是:
    v1         v2                  1          1          1
    ------------------------------------------------------
    这个表的主键是t,x,y
    我总 觉得你用操作参数作为限制条件总有点不太好,
      

  6.   

    --哦,明白了,不过也稍微修改一下SQL> Select * from testa A where not exists(
      2   Select v1 from testa where X=A.X and Y=A.Y and T>A.T );
      

  7.   

    select a.* from testa a
    inner join 
    (select max(t) as t,x,y from testa group by x,y )b
    using( t,x,y);
      

  8.   

    还是以上那个表,假如t代表第"t"次修改(如第1次,第2次....)
    表数据和表结构如下:SQL>   select * from testa;V1         V2                  T          X          Y
    ---------- ---------- ---------- ---------- ----------
    v1         v2                  1          1          1
    f          f                   2          1          1
    jh         h                   1          1          2
    jh         h                   2          1          2
    g          h                   1          4          5
    fgf        fg                  3          4          0
    d          d                   2          1          1
    gfh        hfd                 3          1          1
                                   2          2          2
    fg         fhd                 1          1          5
    f          gf                  2          4          5
    fdg        fgf                 3          4          5现在我要查询第一次修改过,且没有被第2次修改的点;应该怎样实现:
    目标结果应如下:
    V1         V2                  T          X          Y
    ---------- ---------- ---------- ---------- ----------
    g          h                   1          4          5
    fg         fhd                 1          1          5
      

  9.   

    错了,更正一下,目标结果应是:
    V1         V2                  T          X          Y
    ---------- ---------- ---------- ---------- ----------
    fg         fhd                 1          1          5
      

  10.   

    select * from testa t1 where not exists(
    select * from testa where t>1 and t1.x=x and t1.y=y);
      

  11.   

    谢谢,
    你那还要加点条件:
    select * from testa t1 where t=1 and not exists(
    select * from testa where t=3 and t1.x=x and t1.y=y);