X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 64FF29FB92D for ; Fri, 25 Aug 2006 17:16:12 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 61102-07 for ; Fri, 25 Aug 2006 20:16:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.189]) by postgresql.org (Postfix) with ESMTP id 2C5D79FB738 for ; Fri, 25 Aug 2006 17:16:08 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id p77so967418nfc for ; Fri, 25 Aug 2006 13:16:07 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=XRJd/jXc+zX9NaSm8O5XjGrmaDlPAsdpKnTNykVrsWkX4hTGiX/Ml/6IFKsKrlviBIU6Tpbe1Sq+AeDgLu52Jlxv1B/UU4+02aiIGzl/FK4Z4OZi0y8bjyzyYjXP/YZNRAziEyuA4r0q/2qk556w3btcz1/M4MkVqRRJd+j41Zk= Received: by 10.49.8.10 with SMTP id l10mr5871175nfi; Fri, 25 Aug 2006 13:16:07 -0700 (PDT) Received: by 10.48.243.12 with HTTP; Fri, 25 Aug 2006 13:16:07 -0700 (PDT) Message-ID: <2bffcc330608251316g6ed00710u6e43b243800c6087@mail.gmail.com> Date: Fri, 25 Aug 2006 16:16:07 -0400 From: "Henry Ortega" To: pgsql-sql@postgresql.org Subject: Best way to do this query.. MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_12210_6450054.1156536967620" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.2 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE, HTML_MESSAGE, SPF_PASS X-Spam-Level: X-Archive-Number: 200608/201 X-Sequence-Number: 26159 ------=_Part_12210_6450054.1156536967620 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline I have the following: name effective tstamp rate John 01-01-2006 2005-12-07 13:39:07.614945 115.00 John 01-16-2006 2006-01-07 13:39:07.614945 125.00 John 01-16-2006 2006-01-09 15:13:04.416935 1885.00 I want the output to be: name effective end_date rate John 01-01-2006 01-15-2006 115.00 John 01-16-2006 1885.00 What is the best way to do this? This is on a huge table and what I have right now is quite slow. Any ideas? ------=_Part_12210_6450054.1156536967620 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I have the following:

name      effective         tstamp                                   rate
John       01-01-2006     2005-12-07 13:39:07.614945    115.00
John       01-16-2006     2006-01-07 13:39:07.614945     125.00
John       01-16-2006     2006-01-09 15:13:04.416935    1885.00

I want the output to be:
name      effective         end_date        rate
John       01-01-2006     01-15-2006    115.00
John       01-16-2006                         1885.00

What is the best way to do this? This is on a huge table and what I
have right now is quite slow. Any ideas?


------=_Part_12210_6450054.1156536967620--