现在我有一张book表,有bname,bnum俩个字段。bnum中有重复字段。
如:人民教育(2011年-第5期) 4489365 
    人民教育(2011年-第8期) 4489365 
    人民教育(2011年-第9期) 4489365 
    人民教育(2011年-第10期) 4489365 。
我想在表中去除bnum重复的数据。只留一条。

解决方案 »

  1.   

    select t.bnum,(select top 1 bname from srcTable where bnum = t.bnum)B from srcTable t order by bnum
      

  2.   

    只留一条留那一条呢?bname都不一样,随便哪一个都可以吗?还是有什么要求呢?
      

  3.   


    CREATE TABLE book
    (
    bname VARCHAR(100),
    bnum VARCHAR(100)
    )
    GO
    INSERT INTO book
    SELECT '人民教育(2011年-第5期)', '4489365' UNION
    SELECT  '人民教育(2011年-第8期)', '4489365' UNION
    SELECT '人民教育(2011年-第9期)', '4489365' UNION
    SELECT '人民教育(2011年-第10期)', '4489365'GOselect bname,
           bnum
    from book t
    where bname in(select top 1 bname from book where bnum=t.bnum order by bname desc)
      

  4.   

    随便取一条就容易了,比如bname取按ASCII计算最小的一行:select min(bname) as BookName,bnum from book group by bnum