Database of the latest data in the table out of time

The following only do notes

Consider the following table [FM_ALARM]
Database of the latest data in the table out of time

RES_ID : 资源的唯一标识
OCCUR_TIME : 发生时间(毫秒时间戳)
SEVERITY : 告警级别

Real-time data will change, I want to remove the latest record of all data, you can use the following SQL

select res_id, severity
  from fm_alarm t
 where not exists (select 1
          from fm_alarm
         where t.res_id = res_id
           and t.occur_time < occur_time)

Guess you like

Origin blog.51cto.com/dengshuangfu/2401461