Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 29C63B5DC1D for ; Sat, 4 Jun 2011 23:10:55 -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 97997-01 for ; Sun, 5 Jun 2011 02:10:47 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f46.google.com (mail-fx0-f46.google.com [209.85.161.46]) by mail.postgresql.org (Postfix) with ESMTP id 38365B5DBCD for ; Sat, 4 Jun 2011 23:10:46 -0300 (ADT) Received: by fxm17 with SMTP id 17so1882638fxm.19 for ; Sat, 04 Jun 2011 19:10:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=vx7ZhWrdx6u18aNkAaaheRET4ZSdfgVNNDaQvOdTATI=; b=ak1XXc83mBcbFtMSTrEv2foS8GHjEa88J027nOCIAEZ3e4L8pzhP02Xjh137N8Wyzn Lt6s94SGTj1n7UIO/fLd1MSRQauxmcXdCGG6q9Du27rz3TAdxORHUf+ewuUriFgVmdIO a9cdgVBtjkNMtfjdbAWF/vzVILMeI45XTyi7Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=huGSv3ZkiImsh1UC14jwDacBgdri81l1teTRw6Ardo3PnvWw9AGhL5hJ30xzklgeZK /lscnW4LvFThv9TxtYfog/j+eXVZfxIzYvnhaZVQ+yDV2dDirvrXnYDTp53OAe/mcoWN 81oCZz2k3m+CoPUglUL58Dq8aqIw6uk+JZIp8= MIME-Version: 1.0 Received: by 10.223.20.210 with SMTP id g18mr3806179fab.30.1307239846877; Sat, 04 Jun 2011 19:10:46 -0700 (PDT) Received: by 10.223.1.73 with HTTP; Sat, 4 Jun 2011 19:10:46 -0700 (PDT) In-Reply-To: <20110605013623.GC16254@slacker.ja10629.home> References: <20110603195253.GE1324@slacker.ja10629.home> <20110605013623.GC16254@slacker.ja10629.home> Date: Sat, 4 Jun 2011 19:10:46 -0700 Message-ID: Subject: Re: selecting records X minutes apart From: Richard Broersma To: lists-pgsql@useunix.net Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.888 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201106/16 X-Sequence-Number: 35482 On Sat, Jun 4, 2011 at 6:36 PM, wrote: > 0 =A0 =A0 =A0 20:00 > 0 =A0 =A0 =A0 20:05 > 0 =A0 =A0 =A0 20:08 > 0 =A0 =A0 =A0 20:10 > > I want records, starting from the oldest record (20:00), that are at leas= t 5 > minutes apart. =A0So 20:00, 20:05, 20:10 but 20:08 - 20:05 is only 3 minu= tes so > it is to be ignored. Here is my next guess: --although I guess my use of WITH Recursive is corre= ct 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 =3D Accum_ts.id AND B.ts >=3D Accum_ts.ts - INTERVAL '5 MINUTES' GROUP BY B.id HAVING MIN( B.ts ) <=3D MAX( B.ts )) SELECT id, ts FROM Accum_ts ORDER BY id, ts; --=20 Regards, Richard Broersma Jr.