select count(f1) from tbname group by f1 having(count(f1))>1
--相同的记录 create table #temp(vcMemo varchar(20),vcCount varchar(20)) insert into #temp select vcMemo,count(*) from test group by vcMemo select distinct vcMemo from test where vcMemo in (select vcMemo from #temp where vcCount=2 ) drop table #temp--不同的记录 create table #temp(vcMemo varchar(20),vcCount varchar(20)) insert into #temp select vcMemo,count(*) from test group by vcMemo select * from test where vcMemo in (select vcMemo from #temp where vcCount=1 ) drop table #temp
test 表名 vcMemo 字段名 (你这里等于f1)
DECLARE @T TABLE(f1 INT) INSERT INTO @T SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 3 UNION ALL SELECT 4 SELECT f1,COUNT(F1) as 重复记录次数 FROM @T GROUP BY f1 再根据条件查询是否重复
from tbname
group by f1
having(count(f1))>1
--相同的记录
create table #temp(vcMemo varchar(20),vcCount varchar(20))
insert into #temp
select vcMemo,count(*) from test group by vcMemo
select distinct vcMemo from test where vcMemo in
(select vcMemo from #temp where vcCount=2 )
drop table #temp--不同的记录
create table #temp(vcMemo varchar(20),vcCount varchar(20))
insert into #temp
select vcMemo,count(*) from test group by vcMemo
select * from test where vcMemo in
(select vcMemo from #temp where vcCount=1 )
drop table #temp
vcMemo 字段名 (你这里等于f1)
DECLARE @T TABLE(f1 INT)
INSERT INTO @T
SELECT 1 UNION ALL
SELECT 1 UNION ALL
SELECT 2 UNION ALL
SELECT 2 UNION ALL
SELECT 3 UNION ALL
SELECT 3 UNION ALL
SELECT 4
SELECT f1,COUNT(F1) as 重复记录次数
FROM @T
GROUP BY f1
再根据条件查询是否重复