Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sebpa=# insert into numbers (i) select random() * 5 from generate_series(1,7);
- INSERT 0 7
- sebpa=# select * from numbers;
- id | i
- ------+---
- 4001 | 0
- 4002 | 1
- 4003 | 4
- 4004 | 1
- 4005 | 3
- 4006 | 3
- 4007 | 1
- (7 rows)
- sebpa=# select id, i, sum(i) over( order by id rows between 0 preceding and 4 following) from numbers;
- id | i | sum
- ------+---+-----
- 4001 | 0 | 9
- 4002 | 1 | 12
- 4003 | 4 | 12
- 4004 | 1 | 8
- 4005 | 3 | 7
- 4006 | 3 | 4
- 4007 | 1 | 1
- (7 rows)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement