Re: Select values by interval - Mailing list pgsql-sql

From David G. Johnston
Subject Re: Select values by interval
Date
Msg-id CAKFQuwYwLX9SMvtni5hk7WDN4JneZhApj6ku4txfCK9Q=PwHpA@mail.gmail.com
Whole thread Raw
In response to Re: Select values by interval  (Andreas Kretschmer <akretschmer@spamfence.net>)
Responses Re: Select values by interval  (Andreas Kretschmer <akretschmer@spamfence.net>)
List pgsql-sql
On Mon, Nov 23, 2015 at 10:22 AM, Andreas Kretschmer <akretschmer@spamfence.net> wrote:
Markus Wolters <MarkusWolters@gmx.de> wrote:

> Hi all,
>
> I have a table with value and timestamp columns. What I like to do (but am unable to find a solution) is to select the last(value) timestamp combination in every X minute interval where timestamp is between N and M. Is this possible with pgsql?
>

maybe somethink like

select *, row_number() over (partition by to_char(timestamp, 'yyyy-mm-dd
hh24:mm') order by ... desc) ...


and then pick all with row_number = 1

*untested*

​Unproven but whenever you have a query of this form (row_number = 1) you should consider/test whether using DISTINCT ON with an appropriate ORDER BY clause gives you the answer faster and/or more clearly.

David J.​
 

pgsql-sql by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: Select values by interval
Next
From: Andreas Kretschmer
Date:
Subject: Re: Select values by interval