Re: [GENERAL] Given N, finding the interval of N hours with max(sum(..))

2010-06-17 Thread Leonardo F
>I'm trying to make a query that, given N and a date, gives me the interval of >N hours with the max(sum(...)). select sum(i) as s, timestamp '2010-06-16 00:00:00' + extract(hour from d)::integer/3*3 * interval '1 hour' as sumd from p group by extract(hour from d)::integer/3 where d = '2010-06

Re: [GENERAL] Given N, finding the interval of N hours with max(sum(..))

2010-06-17 Thread stefano bonnin
I have found an initial solution. For an interval N of 3 hours the query can be: select distinct poi,first_value(start_date) OVER w as start_date,first_value(end_date) OVER w as end_date,first_value(the_sum) OVER w from (select poi,t1.ts as start_date, t1.ts + '3 hour'::interval as end_dat