Return-Path: <oracle-l-bounce@freelists.org>
Delivered-To: 2-oracle-l@orafaq.com
Received: (qmail 7165 invoked from network); 12 Sep 2007 08:36:46 -0500
Received: from freelists-180.iquest.net (HELO turing.freelists.org) (206.53.239.180)
  by 69.64.49.119 with SMTP; 12 Sep 2007 08:36:44 -0500
Received: from localhost (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id D26D573F9E9;
 Wed, 12 Sep 2007 08:57:57 -0400 (EDT)
Received: from turing.freelists.org ([127.0.0.1])
 by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 01752-10; Wed, 12 Sep 2007 08:57:57 -0400 (EDT)
Received: from turing (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 4343D7411F7;
 Wed, 12 Sep 2007 08:57:57 -0400 (EDT)
Received: with ECARTIS (v1.0.0; list oracle-l); Wed, 12 Sep 2007 08:13:25 -0400 (EDT)
Received: from localhost (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 54192741605
 for <oracle-l@freelists.org>; Wed, 12 Sep 2007 08:13:25 -0400 (EDT)
Received: from turing.freelists.org ([127.0.0.1])
 by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 22309-09 for <oracle-l@freelists.org>;
 Wed, 12 Sep 2007 08:13:25 -0400 (EDT)
Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.238])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 6C17574161F
 for <oracle-l@freelists.org>; Wed, 12 Sep 2007 08:13:17 -0400 (EDT)
Received: by nz-out-0506.google.com with SMTP id s18so115802nze
        for <oracle-l@freelists.org>; Wed, 12 Sep 2007 05:51:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=beta;
        h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
        bh=CmbOpQgfAiq4Vx1ZSqXv5f2sVw4F6bKt3d0WwJV9T8I=;
        b=cqD4AfTaOibIazVaiXx0rU1O460tA/aQX1cgmizydvkv5ftw+F+eDXfufTREq4sHEcCCD7ytZ8iaCRo4HD5KCJXXs+kYfrplSe9JwezafqCv52nWYWaLGO42smAEUbwJFSlpUp4Zs7NrdZlUynDaufMe0obF24p8LVMCZQtbS94=
DomainKey-Signature: a=rsa-sha1; c=nofws;
        d=gmail.com; s=beta;
        h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
        b=tBcHXHySI8MQinPRLI2gXUzxc12DqfuYaPIzndeSkQ5czxvJl/DPdWDkTmJGM3y7+5EVYSa3tqCAk6HKgA/gdsV77EHGl+7Nnk4G8qmiFWjWygTkfMlwyAs8mwosE8kha1BSuvKNxaPtVa8C1/gKZRz0qNKgtlAzllwnW4x7//o=
Received: by 10.65.233.16 with SMTP id k16mr14628602qbr.1189601510943;
        Wed, 12 Sep 2007 05:51:50 -0700 (PDT)
Received: by 10.64.199.3 with HTTP; Wed, 12 Sep 2007 05:51:50 -0700 (PDT)
Message-ID: <ad3aa4c90709120551u1934310ayae97b69e8a1433ab@mail.gmail.com>
Date: Wed, 12 Sep 2007 07:51:50 -0500
From: "Andrew Kerber" <andrew.kerber@gmail.com>
To: gspier@chiliad.com
Subject: Re: sum of a column (development question)
Cc: sfaroult@roughsea.com, lyallbarbour@sanfranmail.com, oracle-l@freelists.org
In-Reply-To: <7A1E592E-E8E0-477F-B47A-9F380DDD6726@chiliad.com>
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----=_Part_23269_2475327.1189601510902"
References: <20070911173238.4B8D11CE303@ws1-6.us4.outblaze.com>
	 <46E6E971.4060903@roughsea.com>
	 <7A1E592E-E8E0-477F-B47A-9F380DDD6726@chiliad.com>
X-archive-position: 1467
X-ecartis-version: Ecartis v1.0.0
Sender: oracle-l-bounce@freelists.org
Errors-to: oracle-l-bounce@freelists.org
X-original-sender: andrew.kerber@gmail.com
Precedence: normal
Reply-to: andrew.kerber@gmail.com
List-help: <mailto:ecartis@freelists.org?Subject=help>
List-unsubscribe: <oracle-l-request@freelists.org?Subject=unsubscribe>
List-software: Ecartis version 1.0.0
List-Id: oracle-l <oracle-l.freelists.org>
X-List-ID: oracle-l <oracle-l.freelists.org>
List-subscribe: <oracle-l-request@freelists.org?Subject=subscribe>
List-owner: <mailto:steve.adams@ixora.com.au>
List-post: <mailto:oracle-l@freelists.org>
List-archive: <http://www.freelists.org/archives/oracle-l>
X-list: oracle-l
X-Virus-Scanned: Debian amavisd-new at localhost.localdomain
------=_Part_23269_2475327.1189601510902
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

You lost me on that one.  How would ntile apply when he just wants totals
for this year and last year?

On 9/11/07, August Spier <gspier@chiliad.com> wrote:
>
> I was under the impression that NTILE would be more useful ... especially
> if you are in a development cycle and requirements for more sql statements
> are going to surface.
> See
> http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions101.htm#sthref1696
>
> r,
>
> Gus
>
> On Sep 11, 2007, at 3:16 PM, Stephane Faroult wrote:
>
> Lyal
>
>  Wooops. This one should be correct (hopefully):
>
> select sum(case sign(inv_dt - trunc(sysdate, 'YEAR'))
>                          when 1 then ord_tot
>                          when 0 then ord_tot
>                          else 0
>                       end) TY,
>               sum(case sign(inv_dt - trunc(sysdate, 'YEAR'))
>                          when -1 then ord_tot
>                          else 0
>                       end) LY     from ar_inv_hdr
>   where inv_dt between add_months(trunc(sysdate, 'YEAR'), -12) and sysdate
>
> Lyall Barbour wrote:
>
> Hi again,
>     Development question.  User wants the sum of all the purchase orders
> for this year and last year.  I'm trying to get it in the same select
> statement.  I want something like this, but don't know how to get it.
>
> select sum(ord_tot) "TY Invoiced Totals",
>        sum(ord_tot) "LY Invoiced Totals"
> from   ar_inv_hdr
> where  inv_dt between trunc(sysdate, 'YYYY') and sysdate
> and    inv_dt between trunc(sysdate, 'YYYY')-1 and trunc(sysdate,
> 'YYYY')-365
>
> This, obviously, doesn't do what i want, but it's where i've gotten to so
> far.  Do i need to select from the same table twice?
>
> Thanks,
> Lyall
>
>
>
>
>
> --
> http://www.freelists.org/webpage/oracle-l
>
>
>
>


-- 
Andrew W. Kerber

'If at first you dont succeed, dont take up skydiving.'

------=_Part_23269_2475327.1189601510902
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

You lost me on that one.&nbsp; How would ntile apply when he just wants totals for this year and last year?<br><br><div><span class="gmail_quote">On 9/11/07, <b class="gmail_sendername">August Spier</b> &lt;<a href="mailto:gspier@chiliad.com">
gspier@chiliad.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="">I was under the impression that NTILE would be more useful ... especially if you are in a development cycle and requirements for more sql statements are going to surface.
<div><br></div><div>See&nbsp;<font face="Helvetica"><a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions101.htm#sthref1696" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions101.htm#sthref1696
</a></font></div><div><font face="Helvetica"><br></font></div><div><font face="Helvetica">r,</font></div><div><font face="Helvetica"><br></font></div><div><font face="Helvetica">Gus</font></div><div><font face="Helvetica">
<br></font><div><div>On Sep 11, 2007, at 3:16 PM, Stephane Faroult wrote:</div><br><blockquote type="cite"><div style="margin: 0px;">Lyal</div><div style="margin: 0px; min-height: 14px;"><br></div><div style="margin: 0px;">
<span>&nbsp;</span>Wooops. This one should be correct (hopefully):</div><div style="margin: 0px; min-height: 14px;"><br></div><div style="margin: 0px;">select sum(case sign(inv_dt - trunc(sysdate, &#39;YEAR&#39;))</div><div style="margin: 0px;">
<span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>when 1 then ord_tot</div><div style="margin: 0px;"><span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>when 0 then ord_tot</div><div style="margin: 0px;"><span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>else 0
</div><div style="margin: 0px;"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>end) TY,</div><div style="margin: 0px;"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>sum(case sign(inv_dt - trunc(sysdate, &#39;YEAR&#39;))</div><div style="margin: 0px;"><span>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>when -1 then ord_tot</div><div style="margin: 0px;"><span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>else 0</div><div style="margin: 0px;"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>end) LY <span>&nbsp; &nbsp; </span>from ar_inv_hdr
</div><div style="margin: 0px;"><span>&nbsp; </span>where inv_dt between add_months(trunc(sysdate, &#39;YEAR&#39;), -12) and sysdate <span>&nbsp;</span></div><div style="margin: 0px;">Lyall Barbour wrote:</div> <blockquote type="cite">
<div style="margin: 0px;">Hi again,</div><div style="margin: 0px;"><span>&nbsp; &nbsp; </span>Development question.<span>&nbsp; </span>User wants the sum of all the purchase orders for this year and last year.<span>&nbsp; </span>I&#39;m trying to get it in the same select statement.
<span>&nbsp; </span>I want something like this, but don&#39;t know how to get it.</div><div style="margin: 0px; min-height: 14px;"><br></div><div style="margin: 0px;">select sum(ord_tot) &quot;TY Invoiced Totals&quot;,</div><div style="margin: 0px;">
<span>&nbsp;&nbsp; &nbsp; &nbsp; </span>sum(ord_tot) &quot;LY Invoiced Totals&quot;</div><div style="margin: 0px;">from <span>&nbsp; </span>ar_inv_hdr</div><div style="margin: 0px;">where<span>&nbsp; </span>inv_dt between trunc(sysdate, &#39;YYYY&#39;) and sysdate
</div><div style="margin: 0px;">and<span>&nbsp; &nbsp; </span>inv_dt between trunc(sysdate, &#39;YYYY&#39;)-1 and trunc(sysdate, &#39;YYYY&#39;)-365</div><div style="margin: 0px; min-height: 14px;"><br></div><div style="margin: 0px;">
This, obviously, doesn&#39;t do what i want, but it&#39;s where i&#39;ve gotten to so far.<span>&nbsp; </span>Do i need to select from the same table twice?</div><div style="margin: 0px; min-height: 14px;"><br></div><div style="margin: 0px;">
Thanks,</div><div style="margin: 0px;">Lyall</div><div style="margin: 0px; min-height: 14px;"><br></div><p style="margin: 0px; min-height: 14px;"><span>&nbsp;&nbsp;</span><br></p> </blockquote><div style="margin: 0px; min-height: 14px;">
<br></div><div style="margin: 0px; min-height: 14px;"><br></div><div style="margin: 0px;">--</div><div style="margin: 0px;"><a href="http://www.freelists.org/webpage/oracle-l" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.freelists.org/webpage/oracle-l</a></div><div style="margin: 0px; min-height: 14px;"><br></div><div style="margin: 0px; min-height: 14px;"><br></div> </blockquote></div><br></div></div></blockquote></div><br><br clear="all">
<br>-- <br>Andrew W. Kerber<br><br>&#39;If at first you dont succeed, dont take up skydiving.&#39;

------=_Part_23269_2475327.1189601510902--
--
http://www.freelists.org/webpage/oracle-l


