I'm trying to learn SQL so be patient with me. I'm using PostgreSQL 9.3
I want to average a column based on a window of dates. I've been able to write window functions that accomplish this with a set interval
but I'd like to be able to be able to do this with a growing interval
. By this I mean:
average values from date_0 to date_1
average values from date_0 to date_2
average values from date_0 to date_3
..... so date date_0 stays the same and date_x grows and creates a larger sample
I'm assuming there is a better way than running a query for each range I'd like to average. Any advice is appreciated. Thank you.
EDIT
I'm trying to create evenly spaced bins to be used to aggregate values of a table over.
I come to the interval by:
(MAX(date) - MIN(date)) / bins
where date
is the column of a table
and bins
is the number of bins I'd like to divide the table into.
date_0
= MIN(date)
date_n
= MIN(date) + (interval * n)