小编cod*_*tes的帖子

显示当前行“连胜”

我需要在查询中显示每行的连续赢/输,因此根据下表,查询应返回“预期”列。我尝试了一些窗口函数的方法,但没有成功。

create table matches (player text, dt date,  is_winner boolean, expected integer )
insert into matches values
('A', '2019-01-01', TRUE, 0),
('A', '2019-01-03', TRUE, 1),
('A', '2019-01-04', TRUE, 2),
('A', '2019-01-09', FALSE, 0),
('A', '2019-01-10', FALSE, -1),
('A', '2019-01-15', TRUE, 0);
Run Code Online (Sandbox Code Playgroud)
create table matches (player text, dt date,  is_winner boolean, expected integer )
insert into matches values
('A', '2019-01-01', TRUE, 0),
('A', '2019-01-03', TRUE, 1),
('A', '2019-01-04', TRUE, 2),
('A', '2019-01-09', FALSE, 0),
('A', '2019-01-10', FALSE, -1),
('A', '2019-01-15', TRUE, …
Run Code Online (Sandbox Code Playgroud)

postgresql gaps-and-islands

5
推荐指数
1
解决办法
337
查看次数

标签 统计

gaps-and-islands ×1

postgresql ×1