table1  
 
字段:  id    username  userpass  type  
 
        101     sun              sun          yy  
        102     sun              sun          yy  
        105     po                po            uu  
        106     po                po            uu  
 
如何将内容重复的列合为一列  
实现后:  
        101    sun            sun              yy  
        105    po             po                po  

解决方案 »

  1.   

    select min(id), username , userpass , type group by username ,userpass ,type
      

  2.   

    select min(id), username , userpass , type group by username ,userpass ,type
    group by username , userpass , type group by username ,userpass ,type
      

  3.   

    select min(id), username , userpass , type from table group by username ,userpass ,type
      

  4.   

    一条SQL如下:
    -----------------------------------------------------------------------select min(id) as id , username , userpass , type from #TT group by username ,userpass ,type order by id-----------------------------------------------------------------------完整测试代码:
    -----------------------------------------------------------------------create table #TT(
    id int,   
    username varchar(50),  
    userpass varchar(50), 
    type varchar(50)
    ) insert  into #TT
    select  101,'sun','sun','yy'
    union all select  102,'sun','sun','yy'
    union all select  105,'po','po','uu'  
    union all select  106,'po','po','uu'select * from #TTselect min(id) as id , username , userpass , type from #TT group by username ,userpass ,type order by id
    drop table #TT