select sn=indentity(int,1,1),* into #t from [tablename]
select * from #t a where sn=(select top 1 sn from #t where id=a.id and value=2)

解决方案 »

  1.   

    select id,value,other=(select top 1 other from 表 where id=a.id and value=2)
    from 表 a
    where value=2
      

  2.   

    --要改改
    select distinct id,value,other=(select top 1 other from 表 where id=a.id and value=2)
    from 表 a
    where value=2
      

  3.   

    --测试--测试数据
    create table 表(id int,value int,other varchar(10))
    insert 表 select 2,2,'p'
    union all select 2,2,'c'
    union all select 3,2,'c'
    union all select 3,7,'c'
    go--查询
    select distinct id,value,other=(select top 1 other from 表 where id=a.id and value=2)
    from 表 a
    where value=2
    go--删除测试
    drop table 表/*--测试结果id          value       other      
    ----------- ----------- ---------- 
    2           2           p
    3           2           c(所影响的行数为 2 行)
    --*/