现在表T3数据如下:  
id   value
1    AAA
2    AAA
3    AAA
4    BBB
5    BBB
6    BBB
现在要求显示:
2  AAA
5  BBB
应该怎么样实现??

解决方案 »

  1.   

    select min(id),value from t3 where not exists(select 1 from (select min(id)id,value from t3 group by value)a where a.id=t3.id and a.value=t3.value)
    group by value
      

  2.   


    if exists(select 1 from sysobjects where name='tb')
    drop table tb
    go
    create table tb(id int,value varchar(5))
    insert into tb
    select 1, 'AAA' union all
    select 2, 'AAA' union all
    select 3, 'AAA' union all
    select 4, 'BBB' union all
    select 5, 'BBB' union all
    select 6, 'BBB';with t
    as
    (
    select rn=ROW_NUMBER()over(partition by value order by id),*
    from tb
    )
    select ID,value
    from t
    where rn=2ID value
    2 AAA
    5 BBB