[SQL] join tables by nearest timestamp
От | Brice André |
---|---|
Тема | [SQL] join tables by nearest timestamp |
Дата | |
Msg-id | CAOBG12=_YTRw0eSY3uRKZTdEw-B-oxZ2Vi5Dwo+NdDYuc7uv6A@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: [SQL] join tables by nearest timestamp
|
Список | pgsql-sql |
Dear all,
I am running a postgresql 9.1 server and I have a table containing events information with, for each entry, an event type, a timestamp, and additional information.SELECT *
FROM
(SELECT * FROM events WHERE type = 'a' ) as t1
LEFT JOIN LATERAL
(SELECT * FROM events WHERE type = 'b' AND timestamp >= t1.timestamp ORDER BY timestamp LIMIT 1) as t2
ON TRUE;
В списке pgsql-sql по дате отправления: