select distinct * from tb group by a,b having count(*)>1
select a,b from 表 group by a,b having count(1)>1
select * from tb group by a,b having count(*)>1
SELECT * FROM TB T WHERE EXISTS(SELECT 1 FROM TB WHERE A=T.A AND B=T.B)
if OBJECT_ID('tb') is not null drop table tb create table tb(a int,b int) insert tb select 1, 1 union all select 1, 2 union all select 2, 1 union all select 1, 1 --查询所有不重复的数据 select distinct * from tb /* a b 1 1 1 2 2 1 */--查询出那条数据重复 select a,b from tb group by a,b having(COUNT(*)>1) /* a b 1 1 */
if OBJECT_ID('tb') is not null drop table tb create table tb(a int,b int) insert tb select 1, 1 union all select 1, 2 union all select 2, 1 union all select 1, 1 --查询所有不重复的数据 select distinct * from tb /* a b 1 1 1 2 2 1 */--查询出那条数据重复 select a,b from tb group by a,b having(COUNT(*)>1)--2005 select a, b from (select row_number() over(partition by a,b order by a,b) as id, a,b from tb) a where id > 1
from tb
group by a,b
having count(*)>1
from tb
group by a,b
having count(*)>1
create table tb(a int,b int)
insert tb
select 1, 1
union all select 1, 2
union all select 2, 1
union all select 1, 1
--查询所有不重复的数据
select distinct * from tb
/*
a b
1 1
1 2
2 1
*/--查询出那条数据重复
select a,b from tb group by a,b having(COUNT(*)>1)
/*
a b
1 1
*/
create table tb(a int,b int)
insert tb
select 1, 1
union all select 1, 2
union all select 2, 1
union all select 1, 1
--查询所有不重复的数据
select distinct * from tb
/*
a b
1 1
1 2
2 1
*/--查询出那条数据重复
select a,b from tb group by a,b having(COUNT(*)>1)--2005
select a, b from (select row_number() over(partition by a,b order by a,b) as id, a,b from tb) a where id > 1