By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
create table histodureeconnexion ( id serial primary key, iduser int, connexion timestamp, deconnexion timestamp, duree_seconde integer );
insert into histodureeconnexion values
(1,1,'2021-10-20 08:05:00','2021-10-20 08:15:40',640),
(2,1,'2021-10-20 09:25:00','2021-10-20 09:35:00',600),
(3,1,'2021-10-21 08:05:00','2021-10-20 09:35:00',600),
(4,1,'2021-10-21 09:00:00','2021-10-20 09:30:00',1800);
4 rows affected
SELECT *, SUM(duree_seconde) OVER (PARTITION BY connexion::date)
FROM histodureeconnexion;
id | iduser | connexion | deconnexion | duree_seconde | sum |
---|---|---|---|---|---|
1 | 1 | 2021-10-20 08:05:00 | 2021-10-20 08:15:40 | 640 | 1240 |
2 | 1 | 2021-10-20 09:25:00 | 2021-10-20 09:35:00 | 600 | 1240 |
3 | 1 | 2021-10-21 08:05:00 | 2021-10-20 09:35:00 | 600 | 2400 |
4 | 1 | 2021-10-21 09:00:00 | 2021-10-20 09:30:00 | 1800 | 2400 |