例如:
f1
1
1
2
2
3
3
44是没有相同的。1、2、3都有相同的。只显示一条出来。
我要查找相同的记录和不相同的记录。

解决方案 »

  1.   

    select count(f1)
    from tbname
    group by f1
    having(count(f1))>1
      

  2.   


    --相同的记录
    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
      

  3.   

    test    表名
    vcMemo  字段名  (你这里等于f1)
      

  4.   


    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
    再根据条件查询是否重复