工号               日期                  时间   机器
03031601 2009-06-03 00:00:00.000 12:09 04
00000111 2010-07-23 00:00:00.000 12:12 03
03031601 2009-06-06 00:00:00.000 12:09 04
03031601 2009-06-04 00:00:00.000 12:05 04
00000000 2011-01-14 00:00:00.000 11:48 04
00000111 2010-07-16 00:00:00.000 12:16 03
03031601 2009-10-06 00:00:00.000 12:07 03
03031601        2009-10-06 00:00:00.000 12:37 04
找出同一天同一时间段(比如11::0到13:00)出现多次的,比如上面最后两条数据就是我要找出来的,数据量很庞大,有上百的吧,各位帮帮忙

解决方案 »

  1.   

    select 工号,日期
    from tb A
    group by 工号,日期
    having count(*)>1
      

  2.   


    select 工号,日期
    from tb
    where 时间 between '' and ''
    group by 工号,日期
    having count(*) > 1
      

  3.   

     select * from tb a where exsits(select 1 from tb 
                 where 日期=a.日期 and datepart(hh,时间)=datepart(hh,a.时间)
                        and 时间<>a.时间)
      

  4.   

    --找出同一天同一时间段(比如11::0到13:00)出现多次的
    select 工号,日期
    from tb
    group by 工号,日期
    having count(*)>1
      

  5.   

    select 工号,日期
    from tb
    group by 工号,日期
    having count(*)>1
      

  6.   


    select * from tableA where exists 
    (select convert(nvarchar(10),日期,120) from tableA 
     group by convert(nvarchar(10),日期,120),substring(时间,1,2) having count(*)>1)