Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 17EF71D29E4 for ; Thu, 24 May 2012 09:10:42 -0300 (ADT) Received: from mail-ob0-f174.google.com ([209.85.214.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SXWsK-0001Ha-UC for pgsql-sql@postgresql.org; Thu, 24 May 2012 12:10:42 +0000 Received: by obbtb18 with SMTP id tb18so12451609obb.19 for ; Thu, 24 May 2012 05:10:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:references:in-reply-to:mime-version:x-mailer:thread-index:date :message-id:subject:to:content-type:content-transfer-encoding :x-gm-message-state; bh=xbtpofLDQnClTBeF8LOFUbmtywRZo54gzH2rUhQlpLk=; b=kgbmH2aaSAgc6ePAyalHdPs50uNLPCyE3How8aAKMlOiFjHlv8QTh9RawLyjXTwmSP Ab1Sf2P+WziOIqCvNPcc6HtMu2PXG5DO0ojLl/KoxILvs5X25Q8rEeySF+kJmHZzAFrc 2AbtQrsdvjDpxhAEWbEJiPiVb5mFaFoEBDmgAChzaQJ5+ieswg84KJdOsNmkRzb72PaU 0/+BZxUgownMoMVaF5p9ZvTImLqwQYEKC+gKZiKQmtfpjRU68041cBBe1e0jajsTHpyB 9tr+T7ipTrsXrVVDqe/35zXUwjhb9WpKFgoeRvhfwpF2zFezKj8nHZfhQyjNuDsFuACV VAZA== Received: by 10.182.207.41 with SMTP id lt9mr30071099obc.41.1337861428176; Thu, 24 May 2012 05:10:28 -0700 (PDT) From: Elrich Marx References: <73a6b75b83b37093e5e2751fc59c4323@mail.gmail.com> <201205241729.21270.raju@linux-delhi.org> In-Reply-To: <201205241729.21270.raju@linux-delhi.org> MIME-Version: 1.0 X-Mailer: Microsoft Office Outlook 12.0 thread-index: Ac05pNEmKhpVBZhzQZO4SyJiaB+zvQAAVq4g Date: Thu, 24 May 2012 14:10:28 +0200 Message-ID: <43a608eb27c08adad0ae99c3409eb1fd@mail.gmail.com> Subject: Re: Flatten table using timestamp and source To: raju@linux-delhi.org, pgsql-sql@postgresql.org Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQkrulxwNT7cda6YODKPunm9HGzqY9sTtjLx71hf/PrkbG41ksVGekiVj25+rf7zUAPEoVqk X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201205/80 X-Sequence-Number: 36628 HI Raj If source changes, in this case from 1 to 2, then etime would be the last value of stime for source =3D1; So for source 1 it starts at stime 13:00 an= d continues till 13:02 (etime). This should result in 3 records, because source is 1, then 2, then 1 again. I hope this explains ? -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org= ] On Behalf Of Raj Mathur (??? ?????) Sent: 24 May 2012 01:59 PM To: pgsql-sql@postgresql.org Subject: Re: [SQL] Flatten table using timestamp and source On Thursday 24 May 2012, Elrich Marx wrote: > I am quite new to Postgres, so please bear with me. > > I have a table with data in the following format: > > Table name : Time_Source_Table > > 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" > > I=92m trying to get to a result that flattens the results based on > source, to look like this: > > 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" > > 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) and not (1, 13:01:00)? Regards, -- Raj --=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 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql