数据:  
                   
                  id           type       flag  
                  01           send       a  
                  01           send       b  
                  01           send       c  
                  02           send       a  
                  02           send       b  
                  01           rece       a  
                  01           rece       b  
  结果为:  
                  01           send     a  
                  02           send     a  
id和flag是联合主键,要删除id重复的数据,结果如上,sql语句怎么写,并解释一下好吗

解决方案 »

  1.   

    可能需要用到临时表SQL> select * from t2;ID         TYPE                 FLAG
    ---------- -------------------- ----
    01         send                 a
    01         send                 b
    01         send                 c
    02         send                 a
    02         send                 b
    01         race                 a
    01         race                 b7 rows selectedSQL> 
    SQL> select id,type,flag  from (
      2  select id,type,flag,row_number() over(partition by id order by id) rm from t2) a where rm=1;ID         TYPE                 FLAG
    ---------- -------------------- ----
    01         send                 a
    02         send                 a
      

  2.   

    用row_number() 去写一下!应该可以实现!?
      

  3.   

    delete from tablename a
    where row_id<
    (
    select max(rowid) from tablename b
    where a.id=b.id
    )
      

  4.   

    http://space.itpub.net/10768286/viewspace-83463
    方法很多,可以参考这个技术博客
      

  5.   

     select id,type,flag  from (
     select id,type,flag,row_number() over(partition by id order by id) rm from t2) a where rm=1;1楼的partition by id是什么意思, over(partition by id order by id) rm from t2) a 又是什么意思,请指教
    还有5楼的sql语句是什么意思