我的数据库中存在这样的数据:
  xsname jsname xsbj jsbj
  11       bb    kjk   jkj
  11       cc    kjk   dfd
  11       bb    kjk   jkj
我的意思是想对xsname 和 jsname同时去重的同时 还要把其他的字段显示出来,最终结果是:
11 bb kjk jkj
11 cc kjk dfd
就这些分了、如有指教不胜感激
                                        

解决方案 »

  1.   


    use tempdb;
    /*
    create table tb
    (
    xsname int not null,
    jsname nvarchar(10) not null,
    xsbj nvarchar(10) not null,
    jsbj nvarchar(10) not null
    );
    insert into tb(xsname,jsname,xsbj,jsbj)
    values
    (11,'bb','kjk','jkj'),
    (11,'cc','kjk','dfd'),
    (11,'bb','kjk','jkj');
    */
    select distinct *
    from tb;
      

  2.   

    select xsname, jsname, xsbj, jsbj
    from
    (select rn=row_number() over(partition by xsname,jsname order by getdate()),* from tb) t
    where rn=1
      

  3.   

    我是对大量的数据进行操作、而且字段也很多、以上的方法我试了、我的数据库是sql2000的、好像都不好用啊、我现在想直接将别的表中的列都插入进来、但是因为初始表是冗余的、总是显示列不匹配、该怎么办、就是insert table select lm from aa 我该怎么限制条件,比如我新表中有
    11 aa  
    11 bb 
    该如何将班级插入呢谢谢
      

  4.   

    你要确认需要不重复的是哪些列。
    select *
    from tb t
    where not exists (select 1 from tb where a = t.a and b = t.b and c > t.c)
    至于插入
    insert into tb(col1,col2,col3...)
    select col1,col2,col3... from A
    --注意tb表列不能为NULL的。
      

  5.   

    1.distinct
    2.插入时选择列名,根据列名一一匹配