select t1,min(t2) t2 from [Table] group by t1

解决方案 »

  1.   


    select t1,min(t2)from
    (
    select t2 from t group by t2 having count(1)=1
    )a group by t1
    union all
    select min(t1)as t1 ,t2 from t group by t2 having count(1)>1
      

  2.   


    create table #t(t1 Int,t2 Int)
    insert into #t
                    select     1 AS t1,3 AS t2
    union all  select     1, 4
    union all  select     5,2
    union all  select     6,2
    select t1,min(t2) from #t group by t1
      

  3.   

    谢谢大家 ,fa_ge 我想问一下 那个count(1)=1 什么意思 
    还有union all 什么意思
      

  4.   

    union all
    将前后两个结果集完全合并count(1)=1   这个是只有一条记录的意思?
      

  5.   

    各位大哥   请教个问题 
        我表里有两个字段   t1,t2     现在记录为 
        t1             t2 
        1               3 
        1               4 
        5               2 
      6                 2 
    现在想分组显示为 
        t1             t2 
        1               3(4也行,这个无所谓) 
        5               2 
    请问怎么办
    ----------------------------------------------------
    如果把6,2这条记录也加上,可以用
    select t1,max(t2) t2 from tb group by t1
    select t1,min(t2) t2 from tb group by t1但如果没有6,2这条记录,我就搞不清楚楼主的算法了.
      

  6.   

    我是要 
     t1    t2
     6     2
    也不能显示 怎么半
    fa_ge的说法好像有问题 报错误
      

  7.   

    select *
    from table a
    where not exists(select 1 from table a.t2 = t2 and a.t1> t1)
      

  8.   

    create table tb(t1 int,t2 int)
    insert into tb values(1,               3) 
    insert into tb values(1,               4) 
    insert into tb values(5,               2) 
    insert into tb values(6,               2)
    goselect t1 , t2 = max(t2) from tb group by t1
    /*
    t1          t2          
    ----------- ----------- 
    1           4
    5           2
    6           2(所影响的行数为 3 行)
    */select t1 , t2 = min(t2) from tb group by t1
    /*
    t1          t2          
    ----------- ----------- 
    1           3
    5           2
    6           2(所影响的行数为 3 行)
    */drop table tb
      

  9.   

    9楼的兄弟   select 1什么意思 换成 select * 有什么不同