Skip site navigation (1) Skip section navigation (2)

Re: selecting records X minutes apart

From: lists-pgsql(at)useunix(dot)net
To: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: selecting records X minutes apart
Date: 2011-06-04 20:49:55
Message-ID: 20110604204955.GB16254@slacker.ja10629.home (view raw or flat)
Thread:
Lists: pgsql-sql
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(at)useunix(dot)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.

In response to

pgsql-sql by date

Next:From: Kevin CrainDate: 2011-06-05 00:51:18
Subject: Re: selecting records X minutes apart
Previous:From: CharlieDate: 2011-06-04 20:42:33
Subject: Re: [SQL] selecting records X minutes apart

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group