Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 18971 invoked from network); 12 Dec 2008 16:59:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Dec 2008 16:59:17 -0000 Received: (qmail 82520 invoked by uid 500); 12 Dec 2008 16:59:28 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 82505 invoked by uid 500); 12 Dec 2008 16:59:28 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 82496 invoked by uid 99); 12 Dec 2008 16:59:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Dec 2008 08:59:28 -0800 X-ASF-Spam-Status: No, hits=2.6 required=10.0 tests=DNS_FROM_OPENWHOIS,SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Dec 2008 16:59:14 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1LBBLp-0002nW-6K for derby-user@db.apache.org; Fri, 12 Dec 2008 08:58:53 -0800 Message-ID: <20979455.post@talk.nabble.com> Date: Fri, 12 Dec 2008 08:58:53 -0800 (PST) From: MassimoH To: derby-user@db.apache.org Subject: Re: VALUES Query Question In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: MassimoHeitor@gmail.com References: <20970481.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org Thanks so much to both of you! I actually wanted to do a cumulative YTD type query (each row has cumulative data for all months before it), so it was hard to do that with just a simple GROUP BY. This syntax works perfectly: SELECT MONTHS.V , (SELECT SUM(SALES.QUANTITY) FROM SALES WHERE YEAR(BEGINDATE) = 2008 AND MONTH(BEGINDATE) <= MONTHS.V) AS Sales FROM (VALUES 1,2,3,4,5,6,7,8,9,10,11,12) AS MONTHS(V); Knut Anders Hatlen-4 wrote: > > MassimoH writes: > >> I want to do a query like this: >> >> SELECT Months.????, (SELECT SUM(Amount) FROM Sales WHERE SaleMonth = >> Months.????) AS Sales >> FROM (VALUES '2008-01-01', '2008-02-01', '2008-03-01', '2008-04-01', >> '2008-05-01', '2008-06-01', '2008-07-01') AS Months; >> >> However, when I use VALUES in a sub-query, I don't see how to reference >> the >> column. Basically, how can I get the above query to work? > > Hi Massimo, > > You can also rename columns with the AS clause. For instance, you can > replace "AS Months" with "AS Months(x)", and then you can reference the > column as Months.x. > > -- > Knut Anders > > -- View this message in context: http://www.nabble.com/VALUES-Query-Question-tp20970481p20979455.html Sent from the Apache Derby Users mailing list archive at Nabble.com.