28,391
社区成员
发帖
与我相关
我的任务
分享
declare @t table
(
id int,
a varchar(1)
)
insert @t(id, a) values(1,'X')
insert @t(id, a) values(2,'X')
insert @t(id, a) values(3,'Y')
insert @t(id, a) values(4,'Z')
select * from @t where a in (select a from @t group by a having count(*)>1 )
--假设现有一表名为mytable的表,有两字段id、title,title可能会有重复的值,id为标识(自动编号)
--要查询有重复的数据
select * from mytable where [id] not in(select [id] from mytable group by title)
--以上查出来的会少掉一条数据,再根据查出来的title去找这些数据即可