I am trying to aggregate the arrays present in column 'agg' grouping them by product and get the all the events from the last 13 weeks.
for example : the first row value of aggregation should be like : aggregate all the arrays grouping them by product and pick up only the last 13week data. that is from 2/8/2014 to last_13(last 13 week date taking 2/8/2014 as the reference which is 11-10-2013)
I tried the following way but does not work .
select array_cat(a.agg2) over(partition by a.PName order by a.PName ,a.week_date desc rows between 0 preceding and 13 following)
from (
select PName,week_date,array_agg(raw_value) agg2,
from vin_temp_table group by PName,week_date order by PName,week_date desc
)a
EDIT :
query :
select PName,week_date,array_agg(raw_value) agg,
from vin_temp_table group by PName,week_date order by PName,week_date desc
results in the following data
PName week_date agg
5773 2/8/2014 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
5773 2/1/2014 {0,0,0,0,0,0,0,0,0,0,0,0,0}
5773 1/25/2014 {0,0,0,0,0,0,0,0,0,0,0,0,0}
5774 1/18/2014 {0,0,0,0,0,0,0,0,0,0,0,0,0}
5775 1/11/2014 {0,0,0,0,0,0,0,0,0,0,0,0,0}
5776 12/28/2013 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
5776 12/21/2013 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
5776 12/14/2013 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
5776 12/7/2013 {0,0,0,0,0,0,0,0,0,0,0,0,0}
5777 11/30/2013 {0,0,0,0,0,0,0,0,0,0,0,0,0}
5778 11/16/2013 {0,0,0,0,0,0,0,0,0,0,0,0}
5778 11/9/2013 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
5778 11/2/2013 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
Raw data : select * from vin_temp_table
Pname week_date raw_value
5773 10/21/2006 0
5773 10/28/2006 0
5773 11/18/2006 0
5773 11/18/2006 0
5773 1/20/2007 0
5773 5/12/2007 0
5773 7/21/2007 0
5773 7/21/2007 0
5773 8/11/2007 0
5773 8/25/2007 0
5773 9/1/2007 0
I even tried to partitioning using array_agg on Pname and week_date. But was not successful with this one too as the Greenplum version 8.2 was not supporting it.
Could some one help me out ? Thanks.