本帖最后由 Luna0 于 2010-06-19 16:35:47 编辑

解决方案 »

  1.   

    delete from table_name a
    where not exists (select 1 from (select column1,column2,max(date1) date1 from table_name) b
    where a.column1=b.column1 and a.column2=b.column2 and a.date1=b.date1)
      

  2.   


    不好意思,少了group by
    delete from table_name a
    where not exists (select 1 from (select column1,column2,max(date1) date1 from table_name group by column1,column2) b
    where a.column1=b.column1 and a.column2=b.column2 and a.date1=b.date1)
      

  3.   

    第二种方法可以根据rowid来删除
    delete from ttt
     where rowid not in (select rowid
                           from (select id,
                                        id1,
                                        date1,
                                        row_number() over(partition by id, id1 order by id, id1, date1 desc) rn
                                   from ttt)
                          where rn = 1)
      

  4.   


    --row_number() over()来
    select 字段1,字段2,字段3
    (select 字段1,字段2,字段3,row_number() over(partition by 字段1,字段2 order by 字段3) rn
    from tb) a
    where rn=1
    --2
    select * from tb a
    where 字段3 in(select max(字段3) from tb 
    where a.字段1=字段1 and a.字段2=字段2 group by 字段1,字段2)--3
    select * from tb a
    where exists(select 1 from tb where a.字段1=字段1 and a.字段2=字段2 and a.字段3>字段3 )
      

  5.   

    Select col1, col2, max(col3)
    From mytable
    Group by col1, col2;不就行了吗?
      

  6.   


    select *
    from tmp t1
    where rowid =
    (
      select max(rowid)
      from tmp t2
      where t1.id = t2.id and t1.name = t2.name
    )
      

  7.   

    为什么没人发现row_number()函数是SQLSERVER中的,不是Oracle的呢?
    为什么没人指出Group by col1, col2这部分的明显错误呢?,完全说不通的写法。(勋章?假的吧!)
      

  8.   

    作个中间存储吧,临时表或者视图啥的,日期和时间分成两个字段导致有点麻烦KingSunSha的解法是有点问题的
      

  9.   

    1
    row_number()在ORACLE里是存在的2
    这个group by是有些问题 应该是没看清题意疏忽了吧 呵呵
      

  10.   

    有人真正地看懂了贴主的需求吗?我不能确定我的理解符合贴主的最终要求,因为贴主的要求表述前后不一致,比较费解。不过,我认为我对表结构的理解没错,
    表1
      字段1 字段2 字段3 
      a t1 2010-5-5 15:23:30
      b tp 2010-5-5 15:23:30
      c tk 2010-5-5 15:23:30
      d ty 2010-5-5 15:23:30我的理解是这个表有三列,第一、第二都是字符型,第三列是日期(当然包含时间),所以我给出的query得出的结果就是贴主要求的。
    如果贴主告诉我第一列包含象"a t1"这样的字符,而第二第三列分别是日期和时间,那我必须承认我的想象力不够,无法理解表还能这么设计的。另外回楼上的,使用rowid之前必须先理解rowid到底是个什么东西,它只是记录的物理地址,Oracle从来不保证它能用于替代任何基于业务逻辑的排序(比如日期列),所以是不能用于这个例子的。
      

  11.   

    行了。谢谢
    select max(字段3),字段1,字段2 from 表1 group by 字段1,字段2