Skip to content

Instantly share code, notes, and snippets.

@cema-sp
Created October 6, 2016 13:27
Show Gist options
  • Save cema-sp/5fc7c22716a3a68c85d6a8022cbfb033 to your computer and use it in GitHub Desktop.
Save cema-sp/5fc7c22716a3a68c85d6a8022cbfb033 to your computer and use it in GitHub Desktop.
Time series selection
select
d, sum(COALESCE(value,0))
from
generate_series('2016-01-01', '2016-10-01', '1 months'::interval) as "d"
left join
metrics_raw
on
d = date_trunc('months', metrics_raw.timestamp)
where
metrics_raw.type is null OR
metrics_raw.type = 'TRA'
group by d
order by d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment