Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 9CA8E475E82 for ; Tue, 20 Aug 2002 11:36:21 -0400 (EDT) Received: from aragorn.reaumur.absolight.net (ATuileries-113-2-1-126.abo.wanadoo.fr [80.11.216.126]) by postgresql.org (Postfix) with ESMTP id 0B43A475E81 for ; Tue, 20 Aug 2002 11:36:21 -0400 (EDT) Received: from andromede.reaumur.absolight.net (andromede.reaumur.absolight.net [212.43.217.61]) by aragorn.reaumur.absolight.net (Postfix) with ESMTP id 21FD67CA5; Tue, 20 Aug 2002 17:36:25 +0200 (CEST) Date: Tue, 20 Aug 2002 17:34:10 +0200 From: Mathieu Arnold To: Stephan Szabo Cc: pgsql-sql@postgresql.org Subject: Re: sql subqueries problem Message-ID: <104534722.1029864850@andromede.reaumur.absolight.net> In-Reply-To: <20020820073326.S42396-100000@megazone23.bigpanda.com> References: <20020820073326.S42396-100000@megazone23.bigpanda.com> X-Mailer: Mulberry/3.0.0b1 (Win32) X-wazaaa: True, true MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/294 X-Sequence-Number: 9140 >> I've tried, but, as the subselect is an aggregate, I can't get it (maybe >> I don't know enough about it to do it :) > > Right, that'd make it harder. :) > > Hmm, would something like: > > FROM > (select *, > (select sum(ff.montant_ttc/df.taux) from facture ff join > devise as df using (id_devise) where ff.date_creation <= > f.date_creation and ff.id_client=f.id_client > group by ff.id_client) as facture, > (select sum(rr.montant/dr.taux) from remise as rr join > devise as dr using (id_devise) where rr.date_paiement <= > f.date_creation and rr.id_client=f.id_client > group by rr.id_client) as remise > From facture f > ); > > give you something closer to what you want? that's exactly it, I guess that I was not twisted enough for that one :) -- Mathieu Arnold