ID   B   C
1    1   2
1    2   1
2    2   1
2    1   2
3    1   2
3    1   1
怎么以ID字段分组,取C里最小的那条记录,然显示出来
ID   B   C
1    2   1
2    2   1
3    1   1

解决方案 »

  1.   

    select * 
    from 
    tb t
    where not exists
    (
        select 1 from tb where t.id=id and t.C>C
    )
      

  2.   


    select * from 表名 a
    where not exists(select 1 from 表名 where a.id=id and C<a.C)
      

  3.   


    --or
    select a.* from 表名 a,(select id,c=min(c) from 表名 group by id)b
    where a.id=b.id and a.c=b.c
      

  4.   


    create table #t(id int,b int,c int)insert into #t
    select 1,1,2 union all
    select 1,2,1 union all
    select 2,2,1 union all
    select 2,1,2 union all
    select 3,1,2 union all
    select 3,1,1select * 
    from #t as out
    where c = (select min(c) from #t as inn where inn.id = out.id) 
    drop table #t