Given N, finding the interval of N hours with max(sum(..))

From: stefano bonnin <stefano(dot)bonnin(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Given N, finding the interval of N hours with max(sum(..))
Date: 2010-06-17 06:17:33
Message-ID: AANLkTimKVsr8Y5g_ReVAylAiJcWBDwtajTTcEKWgIdMP@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,
I'm trying to make a query that, given N and a date, gives me the interval
of N hours with the max(sum(...)). In others words, given the following
table:

2010-06-16 00:00:00 | 0
2010-06-16 01:00:00 | 2
2010-06-16 02:00:00 | 1
2010-06-16 03:00:00 | 5
2010-06-16 04:00:00 | 7
2010-06-16 05:00:00 | 9
2010-06-16 06:00:00 | 2
2010-06-16 07:00:00 | 0
2010-06-16 08:00:00 | 0
2010-06-16 09:00:00 | 0
2010-06-16 10:00:00 | 1
2010-06-16 11:00:00 | 2
2010-06-16 12:00:00 | 1
2010-06-16 13:00:00 | 1
2010-06-16 14:00:00 | 1
2010-06-16 15:00:00 | 1
2010-06-16 16:00:00 | 1
2010-06-16 17:00:00 | 1
2010-06-16 18:00:00 | 1
2010-06-16 19:00:00 | 1
2010-06-16 20:00:00 | 1
2010-06-16 21:00:00 | 0
2010-06-16 22:00:00 | 3
2010-06-16 23:00:00 | 1

With N = 3 and date = '2010-06-16' for example ... I'd like that the "query"
gives me as response: the interval from 3AM and 5AM.
Any solutions and/or hints?

Thanks in advance.
stefano

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jacek Trzmiel 2010-06-17 07:07:32 Wrong number of empty toast pages
Previous Message Dennis Gearon 2010-06-17 06:02:46 Re: world meaningful date time input