Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id E8B69B63233 for ; Sat, 4 Jun 2011 17:50:03 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 64070-06 for ; Sat, 4 Jun 2011 20:49:56 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from eastrmfepo201.cox.net (eastrmfepo201.cox.net [68.230.241.216]) by mail.postgresql.org (Postfix) with ESMTP id 85466B631C7 for ; Sat, 4 Jun 2011 17:49:56 -0300 (ADT) Received: from eastrmimpo02.cox.net ([68.1.16.120]) by eastrmfepo201.cox.net (InterMail vM.8.01.04.00 201-2260-137-20101110) with ESMTP id <20110604204956.VMRZ32549.eastrmfepo201.cox.net@eastrmimpo02.cox.net>; Sat, 4 Jun 2011 16:49:56 -0400 Received: from slacker.ja10629.home ([68.106.109.147]) by eastrmimpo02.cox.net with bizsmtp id rwpv1g00R3Ar1Vg02wpvZ1; Sat, 04 Jun 2011 16:49:56 -0400 X-CT-Score: 0.00 X-CT-RefID: str=0001.0A020207.4DEA9A74.000C,ss=1,re=0.000,fgs=0 X-CT-Spam: 0 X-Authority-Analysis: v=1.1 cv=yFHAE0zmTawA24Oq7y6/6YtGf/lGoQYA0C3uw5xHDzk= c=1 sm=1 a=z1TLwsU0kBEA:10 a=rNODZyWf3PYA:10 a=PjkiJtDTOQ4A:10 a=ZcFhQy0-F_sA:10 a=8nJEP1OIZ-IA:10 a=sXZhTwfwSKhiTs9RzZXpNQ==:17 a=P6M1L9rJAAAA:8 a=HGuCavxbs8VZvPFyxbEA:9 a=wPNLvfGTeEIA:10 a=V_iEmhlNuOsA:10 a=sXZhTwfwSKhiTs9RzZXpNQ==:117 X-CM-Score: 0.00 Authentication-Results: cox.net; none Received: from wcuddy by slacker.ja10629.home with local (Exim 4.72) (envelope-from ) id 1QSxn9-0004Mg-Jj; Sat, 04 Jun 2011 16:49:55 -0400 Date: Sat, 4 Jun 2011 16:49:55 -0400 From: lists-pgsql@useunix.net To: Richard Broersma Cc: pgsql-sql@postgresql.org Subject: Re: selecting records X minutes apart Message-ID: <20110604204955.GB16254@slacker.ja10629.home> References: <20110603195253.GE1324@slacker.ja10629.home> <20110604191559.GA16254@slacker.ja10629.home> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201106/12 X-Sequence-Number: 35478 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, 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.