1,select * from table where 学号 not in (select max(学号) from table group by 姓名)
2,Delete table where 学号 not in (select max(学号) from table group by 姓名)

解决方案 »

  1.   

    1,select 学号,姓名 from table1 where 姓名 in (select 姓名 from table1 group by 姓名 having sum(姓名)>1)
    2 select * from table1 where 学号 in(select max(学号),姓名 from table1 group by 姓名)
      

  2.   

    1,select * from table1 where 姓名 in (select 姓名 from table1 group by 姓名 having count(姓名)>1)
    2 delete from table1 where 学号 not in(select max(学号),姓名 from table1 group by 姓名)
      

  3.   

    1   sensoyr
        2   sensory
        3   test
        3   test
        4    cow
        4    cow
        4    cow的情况 写错了 我去年的面试题
      

  4.   

    1`select  *  from table1 where 学号 in(select 学号,姓名 from table1 group by 学号,姓名 having count(*)>1)
    2删除需要借助临时表了。我没有想到不用临时表的方法。
      

  5.   

    1`select  *  from table1 where 学号 in(select 学号,姓名 from table1 group by 学号,姓名 having count(*)>1)
    2删除需要借助临时表了。我没有想到不用临时表的方法。
      

  6.   

    select 学号,姓名
      into newtable
      from yourtable
      group by 学号,姓名
     
    drop table yourtable
    exec sp_rename newtable,yourtable
      

  7.   


    上面一位大侠的代码很好,也可以这样:
    select 学号,姓名
      into #newtable  --在表名前加‘#’,并将不重复的记录加入其中
      from yourtable
      group by 学号,姓名
    go
    truncate table yourtable
    go
    insert yourtable
    select *
    from #newtable
      

  8.   

    重复值(转蚂蚁的:)如果有ID字段,就是具有唯一性的字段delect table where id not in (  select max(id) from table group by col1,col2,col3...
    )
    group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。2,如果是判断所有字段也可以这样
      select * into #aa from table group by id1,id2,....
      delete table 
      insert into table 
      select * from #aa3,没有ID的情况select identity(int,1,1) as id,* into #temp from tabel
    delect # where id not in (
      select max(id) from # group by col1,col2,col3...)
    delect table
    inset into table(...)
       select ..... from #temp
    col1+','+col2+','...col5 联合主键
    select * from  table where col1+','+col2+','...col5 in (  select max(col1+','+col2+','...col5) from table 
    where having count(*)>1
    group by col1,col2,col3,col4 
    )
    group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。2,
    select identity(int,1,1) as id,* into #temp from tabel
    select * from  #temp where id in (
      select max(id) from #emp where having count(*)>1 group by col1,col2,col3...)
      

  9.   

    1。将表中重复的行选出来select * from 表 where 姓名 in (select 姓名 from 表 group by 姓名 having sum(1)>1)2。要求删除重复的行(多余的) 保留一个!!delete 表 where 学号 not in (select min(学号) from 表 group by 姓名)