数据库之取出表中最新时间的数据
更新:HHH   时间:2023-1-7


以下内容仅做备忘

假设有以下表格【FM_ALARM】

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

数据会实时变更,我要取出所有数据的最新一条记录,则可以使用以下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)
返回关系型数据库教程...