X-Original-To: pgsql-sql@postgresql.org Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by postgresql.org (Postfix) with SMTP id D5C094760CC for ; Fri, 7 Mar 2003 08:15:30 -0500 (EST) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Fri Mar 07 14:15:33 2003 +0100 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id OAA22669; Fri, 7 Mar 2003 14:15:33 +0100 (MET) Message-ID: <3E689B74.703028EF@rodos.fzk.de> Date: Fri, 07 Mar 2003 14:15:32 +0100 From: Christoph Haller X-Mailer: Mozilla 4.77 [en] (X11; U; HP-UX B.10.20 9000/780) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Cc: m@mat.cc Subject: Re: problem with subselect Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Archive-Number: 200303/191 X-Sequence-Number: 12231 > > I have this : > > 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) > > which does not work... telling me that > > "Sub-SELECT uses un-GROUPed attribute f.date_creation from outer query" > Which is not really true, but some way is... > > 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... :) > Try ... GROUP BY mois ; Regards, Christoph