select min(id),username,age from 表 group by username,age

解决方案 »

  1.   

    select id,username into #t from a group by username having count(*)>1
    delete from (select * from a where username in(select username from #t)) a where a.id notin (select id from #t)
    试试应该好使
      

  2.   

    delete from a where username in (select username from a group by username having count(username )>=2)
      

  3.   

    TO:一楼
    group by username,age 好像不行,你看给的数据他俩的都不一样
      

  4.   

    delete from a where id not in (select id from (select min(id)as id,username from a group by username ) b)
    这个好使测试过
      

  5.   

    select * from taa 
    where id not in(select min(id) from taa group by username,age)
      

  6.   

    select distinct * 
    into #a 
    from a 
    where username in 
    (select max(username) 
    from a
    group by username
    having (*)>1)delete a from a a,#a b where a.username=b.username and a.age=b.age insert into 
    a (usernaem,age)
    select username,age from #a 
      

  7.   

    删除重复的记录,只剩下一条
    delete from table1
    from (select max(c)as cc,a,b from table1 group by a,b having count(*) > 1) as table_1
    where (table1.c <> table_1.cc) and (table1.a = table_1.a) and (table1.b = table_1.b)
      

  8.   

    delete from a 
    where id not in (select min(id)as id ,username,age from a group by username,age)
      

  9.   

    delete from a where id not in (select max(id) as id from a group by username)
      

  10.   

    Select Max(id), username Into #Table From table Group by username 
    Delete From table Where id not In (Select id #table)
    Drop table #Table