选择同一天的最后一个 ID 值

Selecting last ID value of the same day

我有一个示例 table 如下所示

ID 日期 信息
1 15.02.2020 一个
2 15.02.2020 b
1 15.02.2020 c
1 15.02.2020 d
3 15.02.2020 e
1 16.02.2020 f
3 16.02.2020
3 16.02.2020 h

我需要创建一个 select 语句来显示同一天每个 ID 的最后一行。 如下所示。

ID 日期 信息
2 15.02.2020 b
1 15.02.2020 d
3 15.02.2020 e
1 16.02.2020 f
3 16.02.2020 h

如何在 Oracle 中管理它 SQL?

一种方法使用相关子查询:

select t.*
from t
where t.id = (select max(t2.id)
              from t t2
              where t2.info = t.info and t2.date = t.date
             );

您还可以使用 window 函数:

select t.*
from (select t.*,
             row_number() over (partition by info, date order by id desc) as seqnum
      from t
     ) t
where seqnum = 1;