Skip to content

Instantly share code, notes, and snippets.

@neslinesli93
Last active October 12, 2019 09:29
Show Gist options
  • Save neslinesli93/6ddf12f7841441ac912c746e1399916a to your computer and use it in GitHub Desktop.
Save neslinesli93/6ddf12f7841441ac912c746e1399916a to your computer and use it in GitHub Desktop.
WITH values as (
SELECT
0 as value,
'' as label,
to_date('00000101','YYYYMMDD') as time
UNION ALL
SELECT
(close - open) / close as value,
to_char(time, 'Mon') || ' ' || to_char(time, 'YYYY') as label,
time
FROM "Tickers_Data"
WHERE extract(dow from time) = $1 AND ticker = $2
)
SELECT
label,
sum(value) over (order by time asc rows between unbounded preceding and current row) as cumulative
FROM values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment