楼主第一条和第三条都是错的,
第一条应这样写:
delete t2 from aa t2 where col3 < (select max(col3) from aa 
where col1 = t2.col1 and col2 = t2.col2)
or 
delete t2 from aa t2 where exists(select 1 from aa 
where col1 = t2.col1 and col2 = t2.col2 and col3>t2.col3)

解决方案 »

  1.   

    恩,我发现了,这样改一下就好
    delete from aa where col3 < (select max(col3) from aa t2 
    where aa.col1 = t2.col1 and aa.col2 = t2.col2)各位没有做过这样的性能比较吗?
      

  2.   

    第三条见笑了,这样写才可以,不过没什么意思了
    delete t1 from aa t1 left join (select max_col3 = max(col3) from aa group by col1,col2) t2 on t1.col3 = t2.max_col3
    where t2.max_col3 is null
      

  3.   

    为什么呢?
    eager spool 和 lazy spool 有什么区别呢?
      

  4.   

    我執行第一條命令後,還是有重複的,無法建立KEY阿
      

  5.   

    --试了一下,"客户统计"上显示下面的快一些
    begin tran
    delete aa
    where exists
    ( select 1
    from aa as tt
    where aa.col1=tt.col1
    and aa.col2=tt.col2
    and aa.col3>tt.col3)
    /*
    delete from aa where col3 < (select max(col3) from aa t2 
    where aa.col1 = t2.col1 and aa.col2 = t2.col2)
    */
    select * from aa
    rollback tran