select * 
from  tb t
where not exists(select 1 
                 from tb
                 where device_id=t.device_id and port_id=t.port_id and  occut_time>t.occut_time)

解决方案 »

  1.   

    select * 
    from  tb t
    where 
    occut_time=(select MAX(occut_time)
                from tb
                where device_id=t.device_id 
                and port_id=t.port_id)
      

  2.   

    try~~
    select m.device_id, m.port_id,m.occur_time,m.status
    from tab M
    left join
    (
    select device_id, port_id, max(occur_time)
    from tab
    group by device_id, port_id) N
    on m.device_id=n.device_id
    and m.port_id=n.port_id
    and m.occur_time=n.occur_time