Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > CREATE TABLE IF NOT EXISTS RECORDS ( > ID INT, > T TIME > ); > INSERT INTO RECORDS VALUES > (1,'12:10:00'), > (1,'12:10:05'), > (1,'12:11:00'), > (1,'13:04:03'), > (2,'14:18:05'), > (2,'15:00:09'), > (3,'17:33:50'), > (1,'20:03:14'), > (1,'20:03:55'), > (1,'20:10:23'); > > > <pre> > ✓ > 10 rows affected > </pre> <!-- --> > SELECT DISTINCT tt.ID, FIRST_VALUE(t) OVER W AS start > FROM (SELECT t.*, > ROW_NUMBER() OVER(ORDER BY t) > - ROW_NUMBER() OVER(PARTITION BY ID ORDER BY t) AS rn > FROM (SELECT ID, t FROM records) t) tt WINDOW W AS > (PARTITION BY rn ORDER BY t ROWS > BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) > ORDER BY start > > <pre> > id | start > -: | :------- > 1 | 12:10:00 > 2 | 14:18:05 > 3 | 17:33:50 > 1 | 20:03:14 > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=postgres_11&fiddle=19f7871114b49935bb0e2314b263e598)*
back to fiddle