select a,b,max(c) as c from t1 group by a,b

解决方案 »

  1.   

    楼上的查询语句有点儿问题,查询出的结果是:
    1 2 t
    2 6 t
    按照下面的写法应该可以满足要求:create table #t(a varchar(10),b varchar(10),c varchar(10))
    insert into #t values ('1','2','t')
    insert into #t values ('1','2','a')
    insert into #t values ('2','6','b')
    insert into #t values ('2','6','t')
    insert into #t values ('2','6','8')
    select *,identity(int,1,1) as tid into #tt from #t
    select a,b,c from #tt where tid in(select min(tid) from #tt group by a,b)
    drop table #tt
    drop table #t
      

  2.   

    如果表1;
       a   b  c  
       1   2  t   
       1   2  a
       2   6  b 
       2   6  t
       2   6  8
    表2:
       a  b  c 
       1  2  t
       1  2  b
       1  3  y
       1  4  h
       2  5  j
       2  5  u
    要得到:
       a  b  c 
       1  2  t
       2  6  b
       1  3  y
       1  4  h
       2  5  j
    那要怎么做?
      

  3.   

    select a,b,max(c) as c from (
    select 表一.* from 表一
    union select 表二.* from 表二
    )t1 group by a,b