X-Original-To: pgsql-sql@postgresql.org Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id C923D476705 for ; Fri, 7 Mar 2003 12:49:47 -0500 (EST) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 2884952; Fri, 07 Mar 2003 09:49:38 -0800 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Mathieu Arnold , pgsql-sql@postgresql.org Subject: Re: problem with subselect Date: Fri, 7 Mar 2003 09:48:45 -0800 User-Agent: KMail/1.4.3 References: <2063882566.1047045882@andromede.reaumur.absolight.net> In-Reply-To: <2063882566.1047045882@andromede.reaumur.absolight.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200303070948.45070.josh@agliodbs.com> X-Archive-Number: 200303/205 X-Sequence-Number: 12245 Mathieu, > SELECT date_trunc('month', f.date_creation) as mois, > sum(f.montant_ttc / d.taux) as facture, > (SELECT sum(f2.montant_ttc / d2.taux) as facture2 > FROM facture AS f2 JOIN devise AS d2 USING (id_devise) > WHERE date_trunc('month', f2.date_creation) > <= date_trunc('month', f.date_creation)) > FROM facture AS f JOIN devise AS d USING (id_devise) > GROUP BY date_trunc('month', f.date_creation) > "Sub-SELECT uses un-GROUPed attribute f.date_creation from outer query" > Which is not really true, but some way is... Hmmm ... this looks like a minor parser bug. What Postgres version are you using? > What I want is to get the sum of the month, and the sum of the month and > the previous. > > If someone has a clue, something, anything... :) Sure. Try putting the sub-select in the FROM clause, instead of the SELECT; that should un-confuse the parser about the grouping. -- Josh Berkus Aglio Database Solutions San Francisco