22,209
社区成员
发帖
与我相关
我的任务
分享
create table #
(a int,b int,c int,d int, e int)
insert into # select 1,2,3,4,5 union all
select 2,2, 3, 4, 6 union all
select 1, 2, 5, 7, 9 union all
select 3, 4, 6, 7, 8 union all
select 1, 3, 5, 9, 8 union all
select 2,5,5,5,5 union all
select 2,5,5,5,5
declare @table table (a int,b int,c int,d int,e int)
insert into @table
select 1,2,3,4,5 union all
select 2,2,3,4,6 union all
select 1,2,5,7,9 union all
select 3,4,6,7,8 union all
select 1,3,5,9,8
select bb.* from (select a,b from @table group by a,b having (count(1)=1))
aa left join @table bb on aa.a=bb.a and aa.b=bb.b
/*
a b c d e
----------- ----------- ----------- ----------- -----------
1 3 5 9 8
2 2 3 4 6
3 4 6 7 8
*/
create table tb (a int,b int,c int,d int,e int)
insert into tb
select 1 ,2 ,3, 4, 5 union all
select 2 ,2 ,3, 4, 5 union all
select 1 ,2 ,5, 6, 7 union all
select 3 ,4 ,3, 4, 5 union all
select 1 ,3 ,5, 9, 8
select * from tb a
where not exists(select 1 from
(select a,b from tb group by a,b having count(1)>1) b where b.a=a.a and b.b=a.b)
/*
a b c d e
----------- ----------- ----------- ----------- ----
2 2 3 4 5
3 4 3 4 5
1 3 5 9 8
select * from tb a
where not exists(select 1 from
(select a,b from tb group by a,b having count(1)>1) b where b.a=a.a and b.b=a.b)
--不好意思上边写错了
select distinct(a),distinct(b),c,d,e
from table
group by c,d,e
select distinct(a),dictinct(b),c,d,e
from table
group by c,d,e