From: lists-pgsql@useunix.net
To: Richard Broersma <richard.broersma@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: selecting records X minutes apart
Date: Sat, 4 Jun 2011 16:49:55 -0400
Message-ID: <20110604204955.GB16254@slacker.ja10629.home> (raw)
In-Reply-To: <BANLkTi=3nSFEc_k1QRMCQyws1ZKCH+gQ4Q@mail.gmail.com>
References: <20110603195253.GE1324@slacker.ja10629.home>
<isd5s4$86l$1@reversiblemaps.ath.cx>
<20110604191559.GA16254@slacker.ja10629.home>
<BANLkTi=3nSFEc_k1QRMCQyws1ZKCH+gQ4Q@mail.gmail.com>
Did you mean WHERE in place of your first AND? If so I already had something
like this but it only returns one set, the oldest group of entries for each
ID.
On Sat, Jun 04, 2011 at 01:09:39PM -0700, Richard Broersma wrote:
> On Sat, Jun 4, 2011 at 12:15 PM, <lists-pgsql@useunix.net> wrote:
> > I want to
> > select records grouped by ID, ordered by timestamp, in ascending order so I'm
> > starting with the oldest, that are at least X minutes apart.
>
>
> Here my guess:
>
> SELECT id, ts
> FROM Yourtable AS A
> AND NOT EXISTS ( SELECT *
> FROM Yourtable AS B
> WHERE B.id = A.id
> AND B.ts > A.ts - INTERVAL '5 MINUTES'
> AND B.tx < A.ts )
>
> ORDER BY id, ts;
>
> --
> Regards,
> Richard Broersma Jr.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: lists-pgsql@useunix.net, richard.broersma@gmail.com
Subject: Re: selecting records X minutes apart
In-Reply-To: <20110604204955.GB16254@slacker.ja10629.home>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox