书号     书号     借出日期
015808  薄暮猎人     1/1
015807  薄暮猎人     1/2
015806  薄暮猎人     1/5
015805  薄暮猎人     3/2
030010   审判        3/1
030011   审判        2/3
030012   审判        4/3
030013   审判        3/9
030014   审判        5/5我有很多数据是重复的,请问要如何将书名一样的书号全改成一样的(假设要最小书号),结果如下:
书号     书号     借出日期
015805  薄暮猎人     1/1
015805  薄暮猎人     1/2
015805  薄暮猎人     1/5
015805  薄暮猎人     3/2
030010   审判        3/1
030010   审判        2/3
030010   审判        4/3
030010   审判        3/9
030010   审判        5/5

解决方案 »

  1.   

    update table set 书号="&(select   min(书号)  from   table  group  by   书号  having  count(书号) > 1)&" where 书号<>"&(select   min(书号)  from   table  group  by   书号  having  count(书号) > 1)&" and 书号 in (select   书号  from   table  group  by   书号  having  count(书号) > 1)你测试下,我没测试的,是根据下面这个改动
    查找表中多余的重复记录,重复记录是根据单个字段(书号)来判断
    select * from table
    where 书号 in (select   书号  from   table  group  by   书号  having  count(书号) > 1)
      

  2.   

    create table book(no varchar(6),name varchar(10),bdate varchar(6))insert book
    select '015808',  '薄暮猎人',     '1/1' union all select
    '015807',  '薄暮猎人'    , '1/2'  union all select
    '015806' , '薄暮猎人'   ,  '1/5'  union all select
    '015805' , '薄暮猎人'  ,   '3/2'  union all select
    '030010' ,  '审判'    ,    '3/1'  union all select
    '030011' ,  '审判'   ,     '2/3'  union all select
    '030012' ,  '审判'  ,      '4/3'  union all select
    '030013' ,  '审判' ,       '3/9'  union all select
    '030014' ,  '审判',        '5/5' update book 
    set no = b.no from (select name,min(no) no from book  group by name) b
    where b.name = book.name
    select * from book/*
    no     name       bdate  
    ------ ---------- ------ 
    015805 薄暮猎人       1/1
    015805 薄暮猎人       1/2
    015805 薄暮猎人       1/5
    015805 薄暮猎人       3/2
    030010 审判         3/1
    030010 审判         2/3
    030010 审判         4/3
    030010 审判         3/9
    030010 审判         5/5(所影响的行数为 9 行)
    */