【发布时间】:2018-01-10 05:27:46
【问题描述】:
我有一张带有 timestamp 列 (timestamp with time zone) 的表。我想知道每对连续时间戳之间的间隔的中值长度。
例如,时间戳(在同一天)为08:00、08:10、08:30、09:00,我想要20 minutes,因为连续时间戳之间的中间间隔是 20 分钟。
我一直在尝试使用窗口函数和领先/滞后的东西,但没有成功。
此代码可能有助于设置情境。
CREATE TABLE timestamps (
"timestamp" timestamp with time zone
);
COPY timestamps ("timestamp") FROM stdin;
2017-08-02 08:00:53.550685-00
2017-08-02 08:10:53.550685-00
2017-08-02 08:30:53.550685-00
2017-08-02 09:00:53.550685-00
\.
【问题讨论】:
标签: sql postgresql datetime window-functions postgresql-9.5