Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 9DF10B62952 for ; Fri, 3 Jun 2011 16:53:03 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 72977-03 for ; Fri, 3 Jun 2011 19:52:56 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from eastrmfepo203.cox.net (eastrmfepo203.cox.net [68.230.241.218]) by mail.postgresql.org (Postfix) with ESMTP id 85FB1B62739 for ; Fri, 3 Jun 2011 16:52:56 -0300 (ADT) Received: from eastrmimpo03.cox.net ([68.1.16.126]) by eastrmfepo203.cox.net (InterMail vM.8.01.04.00 201-2260-137-20101110) with ESMTP id <20110603195256.WNAJ32702.eastrmfepo203.cox.net@eastrmimpo03.cox.net> for ; Fri, 3 Jun 2011 15:52:56 -0400 Received: from slacker.ja10629.home ([68.106.109.147]) by eastrmimpo03.cox.net with bizsmtp id rXst1g00C3Ar1Vg02Xstum; Fri, 03 Jun 2011 15:52:56 -0400 X-CT-Score: 0.00 X-CT-RefID: str=0001.0A020205.4DE93B98.0029,ss=1,re=0.000,fgs=0 X-CT-Spam: 0 X-Authority-Analysis: v=1.1 cv=DkLg0PgY2o4lZqvIebXfT14XCAMsRf7aiPsXd65v5So= c=1 sm=1 a=z1TLwsU0kBEA:10 a=EanDmKbXnS0A:10 a=PjkiJtDTOQ4A:10 a=ZcFhQy0-F_sA:10 a=kj9zAlcOel0A:10 a=sXZhTwfwSKhiTs9RzZXpNQ==:17 a=UkAvxKNXJzF_Go1ePssA:9 a=CjuIK1q_8ugA: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 1QSaQP-0002ri-3R for pgsql-sql@postgresql.org; Fri, 03 Jun 2011 15:52:53 -0400 Date: Fri, 3 Jun 2011 15:52:53 -0400 From: lists-pgsql@useunix.net To: pgsql-sql@postgresql.org Subject: selecting records X minutes apart Message-ID: <20110603195253.GE1324@slacker.ja10629.home> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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/4 X-Sequence-Number: 35470 I have a table that, at a minimum, has ID and timestamp columns. Records are inserted into with random IDs and timestamps. Duplicate IDs are allowed. I want to select records grouped by ID, ordered by timestamp that are X minutes apart. In this case X is 5. Note, the intervals are not X minute wall clock intervals, they are X minute intervals from the last accepted record, per-id. For instance here is some sample input data: ID TS (HH:MM) ------------------- 0 20:00 1 20:03 1 20:04 0 20:05 1 20:05 0 20:08 1 20:09 0 20:10 I'd want the select to return: ID TS (HH:MM) ------------------- 0 20:00 0 20:05 0 20:10 1 20:03 1 20:09 Does my question make sense? Thanks in advance, Wayne