相关疑难解决方法(0)

将两个事件表合并为一个时间线

给定两个表:

CREATE TABLE foo (ts timestamp, foo text);
CREATE TABLE bar (ts timestamp, bar text);
Run Code Online (Sandbox Code Playgroud)

我想编写一个查询,对于回报值tsfoo以及bar代表最新的值的统一视图。换句话说,如果foo包含:

ts | foo
--------
1  | A
7  | B
Run Code Online (Sandbox Code Playgroud)

bar包含:

ts | bar
--------
3  | C
5  | D
9  | E
Run Code Online (Sandbox Code Playgroud)

我想要一个返回的查询:

ts | foo | bar
--------------
1  | A   | null
3  | A   | C
5  | A   | D
7  | B   | D
9  | B …
Run Code Online (Sandbox Code Playgroud)

postgresql join window-functions

12
推荐指数
1
解决办法
2992
查看次数

标签 统计

join ×1

postgresql ×1

window-functions ×1