请教SQL查询重复记录的方法。
例如有数据表Tb_checkIn有数据列“ID”里有几万条记录,那么如何用SQL语句筛选出6月1日至今列表“ID”里重复的记录?

解决方案 »

  1.   

    SELECT ID FROM TB WHERE TIME>'20200602' GROUP BY ID HAVING COUNT(1)>1
      

  2.   

    提示:列名 'TIME' 无效。
      

  3.   

    汗,这只是我举的例子,具体列名要根据你的表来SELECT ID FROM TB WHERE TIME BETWEEN '20200602' AND GETDATE()
     GROUP BY ID HAVING COUNT(1)>1
      

  4.   


    select *
    from your_table a
    where (select count(1) from your_table where id = a.id)>1
    order by id
      

  5.   


    --换成你的表名吧,加多个时间条件
    select *
    from Tb_checkIn a
    where (select count(1) from Tb_checkIn where id = a.id)>1
    and 时间字段 > '20200602'
    order by id
      

  6.   


    --ID为空?
    select *
    from Tb_checkIn a
    where (select count(1) from Tb_checkIn where id = a.id)>1
    and 时间字段 > '20200602'
    and id is not null
    order by id
      

  7.   


    不行啊,is not null过滤不掉
      

  8.   

    你得看是哪个不能为NULL吧自己改
      

  9.   

    我是这样改的and ZhengJian is not null,但是显示出来还是如下图 
      

  10.   

    ZhengJian is not null AND ZhengJian <>''
      

  11.   

    select * from table where id in(select id FROM table  GROUP BY ID HAVING COUNT(1)>1) where zhaoPian is not null
      

  12.   


    and isnull(ZhengJian,'')<>''