Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id DF5B81643863 for ; Thu, 24 May 2012 06:02:11 -0300 (ADT) Received: from mail-yw0-f46.google.com ([209.85.213.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SXTvt-0006ds-KI for pgsql-sql@postgresql.org; Thu, 24 May 2012 09:02:11 +0000 Received: by yhmm54 with SMTP id m54so7515086yhm.19 for ; Thu, 24 May 2012 02:01:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:mime-version:x-mailer:thread-index:date:message-id:subject:to :content-type:x-gm-message-state; bh=1SAKLrmtXUv06ZHzG7KDGwUCGfNghvaEJsv9LONbEj4=; b=mr6Pod5uwbi3VwL3SzAxwA4WuH7idnf8+qE2qyDebCtRa0WVhqB402UV5zPeJCPC32 pij8p0LHj6N/5xCcTojqNtx7yObYt8xfjKxMYSMqkAJzyKO0bub1IOE2SnXUsInUTUHv WnXc8t36uMf9BoSMz918rd9RVikvt9wtYO7DUSnTOCk6LATaPvPCSMB2IXYDVLzI8mYJ XiNoSsp5oy2JwQCDEie/RhPlPManBVAau675LDyBMGeS5yMX3j50Ti+n47TiUaGauJZ0 OKWlDxFP64+yyxV3+gvg7TCSW+Zdf6adroytKZT3qf/DTXk4hNEwRiNQOkTFVDniofGn CLqA== Received: by 10.50.135.4 with SMTP id po4mr15677626igb.60.1337850116100; Thu, 24 May 2012 02:01:56 -0700 (PDT) From: Elrich Marx MIME-Version: 1.0 X-Mailer: Microsoft Office Outlook 12.0 thread-index: Ac05i96insb05IpvTiSXMeJkFAajtQ== Date: Thu, 24 May 2012 11:01:56 +0200 Message-ID: <73a6b75b83b37093e5e2751fc59c4323@mail.gmail.com> Subject: Flatten table using timestamp and source To: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary=e89a8f503764eed12a04c0c480c2 X-Gm-Message-State: ALoCoQnIczYPiUJfPY/CFgSQxt9DHDedsJq8XiWlDE34rbyHOU3yCppwZGYel0dipUz4oNO210Xb X-Pg-Spam-Score: -0.7 (/) X-Archive-Number: 201205/78 X-Sequence-Number: 36626 --e89a8f503764eed12a04c0c480c2 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Good day. 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. Any suggestions would be much appreciated. Regards El --e89a8f503764eed12a04c0c480c2 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable

Good day.

=A0

I am quite new to Postgres, so please = bear with me.

=A0

I =A0have a table with= data in the following format:

=A0

Table name : Time_Source_Table

Source= , Stime

1, "2012-05-24 13:00:00"

1, "2012-05-24 13:01:00"

1, &q= uot;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, &q= uot;2012-05-24 13:06:00"

=A0

I=92m trying to get to a result=A0 that flattens the results based on sourc= e, 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"

=A0

Where =A0Etime is the last Stime for the same source.

=A0

Any suggestions would be much appreciate= d.

=A0

Regards

El

--e89a8f503764eed12a04c0c480c2--