From: Richard Broersma <richard.broersma@gmail.com>
To: lists-pgsql@useunix.net
Cc: pgsql-sql@postgresql.org
Subject: Re: selecting records X minutes apart
Date: Sat, 4 Jun 2011 19:10:46 -0700
Message-ID: <BANLkTikWBFevHv9igfGVKNpx792PuKY+KA@mail.gmail.com> (raw)
In-Reply-To: <20110605013623.GC16254@slacker.ja10629.home>
References: <20110603195253.GE1324@slacker.ja10629.home>
<BANLkTikyu3jbxKucoyr_RH-2G6Ouq1H9oA@mail.gmail.com>
<20110605013623.GC16254@slacker.ja10629.home>
On Sat, Jun 4, 2011 at 6:36 PM, <lists-pgsql@useunix.net> wrote:
> 0 20:00
> 0 20:05
> 0 20:08
> 0 20:10
>
> I want records, starting from the oldest record (20:00), that are at least 5
> minutes apart. So 20:00, 20:05, 20:10 but 20:08 - 20:05 is only 3 minutes so
> it is to be ignored.
Here is my next guess: --although I guess my use of WITH Recursive is correct
WITH RECURSIVE Accum_ts( id, ts ) AS
( SELECT id, MIN( ts )
FROM Yourtable
GROUP BY id )
UNION ALL ( SELECT B.id, MIN( B.ts )
FROM Yourtable AS B
WHERE B.id = Accum_ts.id
AND B.ts >= Accum_ts.ts - INTERVAL '5 MINUTES'
GROUP BY B.id
HAVING MIN( B.ts ) <= MAX( B.ts ))
SELECT id, ts
FROM Accum_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: richard.broersma@gmail.com, lists-pgsql@useunix.net
Subject: Re: selecting records X minutes apart
In-Reply-To: <BANLkTikWBFevHv9igfGVKNpx792PuKY+KA@mail.gmail.com>
* 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