把你的结果放在临时表中,
select * from #tb t where not exists(select 1 from #tb where id=t.id and endtime<t.endtime)

解决方案 »

  1.   

    select a.t as endtime,a.id,a.rx,a.tx ,if_name 
    into #tmp
    from (select tr_time as t,hex(box_id) as id,if_name,rx,tx 
          from traffic 
          where tr_time between '2009-01-22 11:00:00' and '2009-01-22 12:05:00' 
          group by tr_time desc,box_id,if_name and if_name='ixp0' 
         ) as a 
    group by a.id 
    select *
    from #tmp a
    where not exists(select 1 from #tmp and convert(char(13),endtime,120) = convert(char(13),a.endtime,120) and endtime < a.endtime)drop table #tmp
      

  2.   

    select a.t as endtime,a.id,a.rx,a.tx ,if_name from (select tr_time as t,hex(box_id) as id,if_name,rx,tx from traffic where tr_time between '2009-01-22 11:00:00' and '2009-01-22 12:05:00' group by tr_time desc,box_id,if_name and if_name='ixp0' ) as a group by a.id 
    having datepart(mi,a.t)%60=0 and datepart(ss,a.t)%60=0
      

  3.   


    select '20'+convert(char(6),tr_time,12)+datepart(hh,tr_time)
    2009041013
    你把时间搞成这种格式的,根据这种格式分组。