--测试数据
declare @t table(personid int,relationid int,name varchar(1),sex varchar(2))
insert into @t
select 1,1,1,'男'
union all select 1,1,1,'女'
union all select 1,2,3,'男'
union all select 1,3,4,'男'
--方法1.如果表中就这几个字段,可以用这种方法
select personid,relationid,name,sex=min(sex)
from @t group by personid,relationid,name
--方法2.适用一表中还有其他字段的情况
select * from @t a
where sex=(select top 1 sex from @t
where personid=a.personid and relationid=a.relationid and name=a.name)
select a.* from temp as a inner join (Select Distinct personid,relationid,name from temp) as b on a.personid=b.personid and a.relationid=b.relationid and a.name=b.name
select a.* from temp as a,(Select Distinct personid,relationid,name from temp) as b where a.personid=b.personid and a.relationid=b.relationid and a.name=b.name