From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Andreas Kretschmer <akretschmer(at)spamfence(dot)net> |
Cc: | "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Select values by interval |
Date: | 2015-11-23 17:25:05 |
Message-ID: | CAKFQuwYwLX9SMvtni5hk7WDN4JneZhApj6ku4txfCK9Q=PwHpA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Mon, Nov 23, 2015 at 10:22 AM, Andreas Kretschmer <
akretschmer(at)spamfence(dot)net> wrote:
> Markus Wolters <MarkusWolters(at)gmx(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Kretschmer | 2015-11-23 17:31:09 | Re: Select values by interval |
Previous Message | Andreas Kretschmer | 2015-11-23 17:22:16 | Re: Select values by interval |