pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Mathieu Arnold <m@mat.cc>
To: pgsql-sql@postgresql.org
Subject: Re: problem with subselect
Date: Fri, 7 Mar 2003 09:48:45 -0800
Message-ID: <200303070948.45070.josh@agliodbs.com> (raw)
In-Reply-To: <2063882566.1047045882@andromede.reaumur.absolight.net>
References: <2063882566.1047045882@andromede.reaumur.absolight.net>

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



view thread (6+ messages)  latest in thread

Message-ID: <200303070948.45070.josh@agliodbs.com>
Permalink:  ../200303070948.45070.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200303070948.45070.josh@agliodbs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, m@mat.cc
  Subject: Re: problem with subselect
  In-Reply-To: <200303070948.45070.josh@agliodbs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox