This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
truncate table events; | |
CREATE TABLE events(ref_id integer, event_type text, ts integer); | |
INSERT INTO events (ref_id, event_type, ts) VALUES (1, 'foo', 1), (1, 'bar', 1), (2, 'foo', 0), (3, 'foo', 0), (1, 'foo', 4), (3, 'foo', 7), (2, 'bar', 10); | |
select | |
ref_id, | |
event_type, | |
ts, | |
first_value(ts) over ( | |
partition by ref_id, event_type order by ts asc rows between 1 following and unbounded following |
OlderNewer