本帖最后由 smilewmr 于 2013-06-04 15:21:26 编辑

解决方案 »

  1.   


    drop table  #t        
    select  58 rownum, 11117 ID,   'ST4-2' bianhao,       Convert(datetime,'2013-05-23 10:07:12') shijian,       11 chazhi 
    into #t
    union all
    select  59, 11116 ,   'ST4-2',       '2013-05-23 10:07:23',       11 union all
    select  60, 11115 ,   'ST4-2',       '2013-05-23 10:07:34',       22 union all
    select  61, 11114 ,   'ST4-2',       '2013-05-23 10:07:56',       11 union all
    select  62, 11113 ,   'ST4-2',       '2013-05-23 10:08:07',       11 union all
    select  63, 11112 ,   'ST4-2',       '2013-05-23 10:08:18',       11 union all
    select  64, 11111 ,   'ST4-2',       '2013-05-23 10:08:29',       11 union all
    select  65, 11110 ,   'ST4-2',       '2013-05-23 10:08:40',       11 union all
    select  66, 11109 ,   'ST4-2',       '2013-05-23 10:08:51',       11 union all
    select  67, 11108 ,   'ST4-2',       '2013-05-23 10:09:02',       88 union all
    select  68, 11107 ,   'ST4-2',       '2013-05-23 10:10:30',       11 union all
    select  69, 11106 ,   'ST4-2',       '2013-05-23 10:10:41',       11 union all
    select  70, 11105 ,   'ST4-2',       '2013-05-23 10:10:52',       11 union all
    select  71, 11104 ,   'ST4-2',       '2013-05-23 10:11:03',       61 union all
    select  72, 11104 ,   'ST4-2',       '2013-05-23 10:12:04',       01 union all
    select  73, 11104 ,   'ST4-2',       '2013-05-23 10:12:05',       01 select  Min(rownum) rownum,min(ID) ID,Min(bianhao) bianhao,Min(shijian) kaishishijian,Max(shijian) jieshushijian
    from
    (
    select *
    ,(
      select min(t3.shijian)
      from #t t3 
      where t1.rownum<t3.rownum
      and t3.chazhi>60
    ) as groupTime
    from #t t1 
    ) t2
    group by groupTime
    order by rownum
    卤煮,我是当修改了测试数据。