X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 5BD0F9FB205 for ; Wed, 20 Sep 2006 14:24:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 96383-01 for ; Wed, 20 Sep 2006 14:24:12 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nz-out-0102.google.com (nz-out-0102.google.com [64.233.162.199]) by postgresql.org (Postfix) with ESMTP id DC2BD9FB2D5 for ; Wed, 20 Sep 2006 14:24:12 -0300 (ADT) Received: by nz-out-0102.google.com with SMTP id 14so156511nzn for ; Wed, 20 Sep 2006 10:24:10 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=nmRF9XVBu7w3mKCm0rxtm+EkeZo8zWtjb6dXDqECCYGqBpvGPDAqt1YRS9awr/HobhGPrMfaQWgtCk3jXmLx6/CTiroz8g1jrYRyHMFxa4cHoIkmuJK+bX2jlm4qgUVeQy2L4ZnhUC7xKmya6zdM890c7HYC7bodTmUKJilnP54= Received: by 10.35.46.11 with SMTP id y11mr28921350pyj; Wed, 20 Sep 2006 10:24:09 -0700 (PDT) Received: by 10.35.80.9 with HTTP; Wed, 20 Sep 2006 10:24:09 -0700 (PDT) Message-ID: Date: Wed, 20 Sep 2006 12:24:09 -0500 From: "Aaron Bono" To: "Becky Hoff" Subject: Re: Dividing results from two tables with different time frames Cc: pgsql-sql@postgresql.org In-Reply-To: <4B2BD8A084A0B442ABF42645DB572A5F28DD52@fr-fs1.StandonInc.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_12332_6930166.1158773049491" References: <4B2BD8A084A0B442ABF42645DB572A5F28DD52@fr-fs1.StandonInc.com> X-Google-Sender-Auth: e95eb4903058fbdf X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.488 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, HTML_50_60, HTML_MESSAGE, SPF_PASS X-Spam-Level: X-Archive-Number: 200609/139 X-Sequence-Number: 26350 ------=_Part_12332_6930166.1158773049491 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/18/06, Becky Hoff wrote: > > The sum(dr.loan_starting_balance + dr.loan_net_change) part of the > calculation have a single date, the last day in a date range chosen by the > user > > > > Sum(ds.pulled_loan_total) and sum(ds.renew_loan_amount) both have a range > of dates chosen by the user > > > > What I need it the result of the second expression divided by the result > of the first expression. > Can you provide some data examples. Show a sample of the data you have to query, what results you are getting and what results you are really wanting so we can see where your queries are not giving you what you need. By your post it sounds like you just need to join your two queries and then use the formula: Sum(ds.pulled_loan_total) and sum(ds.renew_loan_amount) / sum( dr.loan_starting_balance + dr.loan_net_change) but if it were this simple you probably would have it figured out by now. Data examples help us help you much better. ================================================================== Aaron Bono Aranya Software Technologies, Inc. http://www.aranya.com http://codeelixir.com ================================================================== ------=_Part_12332_6930166.1158773049491 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/18/06, Becky Hoff <bhoff@standoninc.com> wrote:

The sum(dr.loan_starting_balance + dr.loan_net_change) part of the calculation have a single date, the last day in a date range chosen by the user

 

Sum(ds.pulled_loan_total) and sum(ds.renew_loan_amount) both have a range of dates chosen by the user

 

What I need it the result of the second expression divided by the result of the first expression.


Can you provide some data examples.  Show a sample of the data you have to query, what results you are getting and what results you are really wanting so we can see where your queries are not giving you what you need.

By your post it sounds like you just need to join your two queries and then use the formula:
Sum(ds.pulled_loan_total) and sum(ds.renew_loan_amount ) / sum(dr.loan_starting_balance + dr.loan_net_change)

but if it were this simple you probably would have it figured out by now.  Data examples help us help you much better.

==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
   http://codeelixir.com
================================================================== ------=_Part_12332_6930166.1158773049491--