This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create materialized view mview | |
as | |
select a.userid, a.balance, d.date | |
from (select d as date from generate_series(timestamp '2023-05-01', '2023-06-2', interval '1 day') d) d | |
join lateral (select userid, balance, date from balance where date <= d.date order by date desc limit 1) a | |
on true union select userid, balance, date from balance order by date; | |
create materialized view mview2 | |
as | |
select a.userid, a.balance, a.date as start, b.date as fin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set nocompatible " be iMproved, required | |
filetype off " required | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
" let Vundle manage Vundle, required | |
Plugin 'VundleVim/Vundle.vim' | |
Plugin 'tpope/vim-fugitive' | |
Plugin 'scrooloose/nerdtree' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT a.user_id, b.balance, d.as_of_date | |
FROM ( | |
SELECT d AS as_of_date | |
FROM generate_series(timestamp '2015-12-29', '2016-01-10', interval '1 hour') d | |
) d | |
JOIN LATERAL ( | |
select user_id, as_of_date | |
from balances | |
where as_of_date <= d.as_of_date | |
order by as_of_date |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import timedelta, datetime | |
from collections import Counter | |
def bin_days(d1, d2): | |
counter = Counter() | |
d_next = d1.replace(hour = 0, minute=0, second=0) + timedelta(days=1) | |
weekday = d1.weekday() | |
counter[weekday] += (d_next - d1).total_seconds() / (24 * 60 * 60) | |
delta = d2 - d_next |
NewerOlder