select distinct GS from tablename

解决方案 »

  1.   

    select * from 表 t
    where ID=(select top 1 ID 
                 from 表 
                     where GS=t.GS 
                         order by ID)
      

  2.   

    select min(ID) AS ID,GS FROM 表名
    group by GS
      

  3.   

    declare @tb table
    (
       ID    varchar(10),
       GS    varchar(20)
    )
    insert @tb
    select 'in113',      '南保' union
    select 'in114',      '南保' union
    select 'in104',      '南平中保' union
    select 'in106',      '南平中保' union
    select 'in105',      '邵武中保' union
    select 'in103',      '邵武中保'    --查询 
    select * from @tb t
    where ID=(select top 1 ID 
                 from @tb 
                     where GS=t.GS 
                         order by ID)
            
    --结果
    /*
    ID         GS                   
    ---------- -------------------- 
    in103      邵武中保
    in104      南平中保
    in113      南保(3 row(s) affected)
    */
      

  4.   

    也不对呀,
    楼主要的: in105     邵武中保,
    不是:     in103     邵武中保
      

  5.   

    呵呵, 不知道LZ是不是写错了。拿出来的ID 没有规律
      

  6.   

    jixiaojie(太多借口)
    只是分组求出了最小的
    可怎么求出前三个呢/
    我哦看不明白
    楼主的我也不太明白
      

  7.   

    select min(id) as id,min(Gs) as Gs from [table] group by Gs
      

  8.   

    --如果是要用顺序排在最前面的,要自己设一个排序的ID字段
    declare @tb table
    (
       ID    varchar(10),
       GS    varchar(20)
    )
    insert @tb
    select 'in113',     '南保' union all
    select 'in114',     '南保' union all
    select 'in104',     '南平中保' union all
    select 'in106',     '南平中保' union all
    select 'in105',     '邵武中保' union all
    select 'in103',     '邵武中保'    
    select * from @tb
    drop table #tempSELECT IDENTITY(int, 1,1) AS ID_Num ,* into #temp FROM @tb select * from #temp
    --结果
    select id,gs from #temp where id_num in( select min(id_num) from #temp group by gs)