select id,value,other=(select top 1 other from 表 where id=a.id and value=2) from 表 a where value=2
--要改改 select distinct id,value,other=(select top 1 other from 表 where id=a.id and value=2) from 表 a where value=2
--测试--测试数据 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 行) --*/
from 表 a
where value=2
select distinct id,value,other=(select top 1 other from 表 where id=a.id and value=2)
from 表 a
where value=2
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 行)
--*/