create table t(id integer, date timestamp with time zone, score float);
insert into t(id, date, score);
INSERT INTO t (id, date, score)
VALUES
(1,'2018-10-10 00:00:00',90),
(2,'2018-10-11 00:00:00',100),
(3,'2018-10-16 00:00:00',89),
(4,'2018-10-17 00:00:00',91),
(5,'2018-10-18 00:00:00',92);
select * from t;
id | date | score
----+------------------------+-------
1 | 2018-10-10 00:00:00+08 | 90
2 | 2018-10-11 00:00:00+08 | 100
3 | 2018-10-16 00:00:00+08 | 89
4 | 2018-10-17 00:00:00+08 | 91
5 | 2018-10-18 00:00:00+08 | 92
(5 rows)
select
t.id,
t.date, t.score
from (
select full_cmp.id1 from (
select
t0.id id0,
t1.id id1
from t t0, t t1
where
t1.date >
t0.date and t1.score > t0.score
order by
t1.date ) full_cmp
group by full_cmp.id1
) cmp, t
where cmp.id1 =
t.idorder by
t.date;