相关疑难解决方法(0)

查询 PostgreSQL 9 中分组连续行的总和

我有关于在不同国家旅行的人的数据,如下所示:

country | begintimestamp      | distance    

Germany | 2015-01-01 00:00:00 | 100
Germany | 2015-01-01 01:12:13 | 30
France  | 2015-01-01 02:13:14 | 40
France  | 2015-01-01 03:14:15 | 20
Spain   | 2015-01-01 04:15:16 | 10
France  | 2015-01-01 05:16:17 | 30
France  | 2015-01-01 05:17:18 | 5
Germany | 2015-01-01 06:18:19 | 3
Run Code Online (Sandbox Code Playgroud)

我需要的是能够收到这样的结果 -distance与最早的连续行相加begintimestamp

country | begintimestamp      | distance

Germany | 2015-01-01 00:00:00 | 130  // 100+30, the distance of two first rows summed. …
Run Code Online (Sandbox Code Playgroud)

postgresql window-functions

8
推荐指数
1
解决办法
3104
查看次数

标签 统计

postgresql ×1

window-functions ×1