Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id B25DD1D29E0 for ; Thu, 24 May 2012 09:00:15 -0300 (ADT) Received: from etc.kandalaya.org ([83.143.86.98] helo=images.kandalaya.org) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SXWiA-0006cc-Pd for pgsql-sql@postgresql.org; Thu, 24 May 2012 12:00:13 +0000 Received: from mail.linux-delhi.org ([120.59.37.175]) by images.kandalaya.org (8.14.3/8.14.3/Debian-9) with ESMTP id q4OBxg7a016177 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 24 May 2012 17:29:45 +0530 Received: from mail.linux-delhi.org (raju@localhost [127.0.0.1]) by mail.linux-delhi.org (8.14.4/8.14.4/Debian-2) with ESMTP id q4OBxL0P021069 for ; Thu, 24 May 2012 17:29:23 +0530 From: "Raj Mathur (=?utf-8?b?4KSw4KS+4KSc?= =?utf-8?b?IOCkruCkvuCkpeClgeCksA==?=)" Reply-To: raju@linux-delhi.org Organization: Kandalaya To: pgsql-sql@postgresql.org Subject: Re: Flatten table using timestamp and source Date: Thu, 24 May 2012 17:29:20 +0530 User-Agent: KMail/1.13.7 (Linux/3.2.0-2-686-pae; KDE/4.6.5; i686; ; ) References: <73a6b75b83b37093e5e2751fc59c4323@mail.gmail.com> In-Reply-To: <73a6b75b83b37093e5e2751fc59c4323@mail.gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201205241729.21270.raju@linux-delhi.org> X-Spam-Status: No, score=-7.5 required=5.0 tests=AWL,BAYES_00, DNS_FROM_RFC_BOGUSMX, LOCAL_FROM_RAJU, RCVD_IN_PBL, RCVD_IN_XBL, RDNS_NONE autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on images.kandalaya.org X-Virus-Scanned: clamav-milter 0.95.2 at images.kandalaya.org X-Virus-Status: Clean X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/79 X-Sequence-Number: 36627 On Thursday 24 May 2012, Elrich Marx wrote: > I am quite new to Postgres, so please bear with me. >=20 > I have a table with data in the following format: >=20 > Table name : Time_Source_Table >=20 > Source , Stime > 1, "2012-05-24 13:00:00" > 1, "2012-05-24 13:01:00" > 1, "2012-05-24 13:02:00" > 2, "2012-05-24 13:03:00" > 2, "2012-05-24 13:04:00" > 1, "2012-05-24 13:05:00" > 1, "2012-05-24 13:06:00" >=20 > I=E2=80=99m trying to get to a result that flattens the results based on > source, to look like this: >=20 > Source, Stime, Etime > 1, "2012-05-24 13:00:00","2012-05-24 13:02:00" > 2, "2012-05-24 13:03:00","2012-05-24 13:04:00" > 1, "2012-05-24 13:05:00","2012-05-24 13:06:00" >=20 > Where Etime is the last Stime for the same source. How do you figure out that the Etime for (1, 13:00:00) is (1, 13:02:00)=20 and not (1, 13:01:00)? Regards, =2D- Raj =2D-=20 Raj Mathur || raju@kandalaya.org || GPG: http://otheronepercent.blogspot.com || http://kandalaya.org || CC68 It is the mind that moves || http://schizoid.in || D17F