Return-Path: <oracle-l-bounce@freelists.org>
Delivered-To: 2-oracle-l@orafaq.com
Received: (qmail 8413 invoked from network); 11 Sep 2007 15:02:12 -0500
Received: from freelists-180.iquest.net (HELO turing.freelists.org) (206.53.239.180)
  by 69.64.49.119 with SMTP; 11 Sep 2007 15:02:07 -0500
Received: from localhost (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 88AD274110F;
 Tue, 11 Sep 2007 15:23:07 -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 11136-04; Tue, 11 Sep 2007 15:23:07 -0400 (EDT)
Received: from turing (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 0811473D1F0;
 Tue, 11 Sep 2007 15:23:06 -0400 (EDT)
Received: with ECARTIS (v1.0.0; list oracle-l); Tue, 11 Sep 2007 14:38:33 -0400 (EDT)
Received: from localhost (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 3CF847413B6
 for <oracle-l@freelists.org>; Tue, 11 Sep 2007 14:30:32 -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 00728-02 for <oracle-l@freelists.org>;
 Tue, 11 Sep 2007 14:30:32 -0400 (EDT)
Received: from smtp20.orange.fr (smtp20.orange.fr [80.12.242.26])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 93F717411DD
 for <oracle-l@freelists.org>; Tue, 11 Sep 2007 14:30:30 -0400 (EDT)
Received: from me-wanadoo.net (localhost [127.0.0.1])
 by mwinf2028.orange.fr (SMTP Server) with ESMTP id 05D581C000BA
 for <oracle-l@freelists.org>; Tue, 11 Sep 2007 21:09:12 +0200 (CEST)
Received: from [192.168.254.50] (AVelizy-152-1-103-22.w90-35.abo.wanadoo.fr [90.35.110.22])
 by mwinf2028.orange.fr (SMTP Server) with ESMTP id CC4A71C000AF;
 Tue, 11 Sep 2007 21:09:11 +0200 (CEST)
X-ME-UUID: 20070911190911836.CC4A71C000AF@mwinf2028.orange.fr
Message-ID: <46E6E971.4060903@roughsea.com>
Date: Tue, 11 Sep 2007 21:16:01 +0200
From: Stephane Faroult <sfaroult@roughsea.com>
User-Agent: Thunderbird 2.0.0.0 (X11/20070326)
MIME-Version: 1.0
To: lyallbarbour@sanfranmail.com
Cc: oracle-l@freelists.org
Subject: Re: sum of a column (development question)
References: <20070911173238.4B8D11CE303@ws1-6.us4.outblaze.com>
In-Reply-To: <20070911173238.4B8D11CE303@ws1-6.us4.outblaze.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-archive-position: 1451
X-ecartis-version: Ecartis v1.0.0
Sender: oracle-l-bounce@freelists.org
Errors-to: oracle-l-bounce@freelists.org
X-original-sender: sfaroult@roughsea.com
Precedence: normal
Reply-to: sfaroult@roughsea.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

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


