From: | Christoph Haller <ch(at)rodos(dot)fzk(dot)de> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Cc: | mat(at)mat(dot)cc |
Subject: | Re: problem with subselect |
Date: | 2003-03-07 14:51:15 |
Message-ID: | 3E68B1E3.7DDEB3E4@rodos.fzk.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
> |> 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)
> |> <=3D 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)
> |>=20
> |> which does not work... telling me that
> |>=20
> |> "Sub-SELECT uses un-GROUPed attribute f.date_creation from outer
> | query"
> |> Which is not really true, but some way is...
> |>=20
> |> What I want is to get the sum of the month, and the sum of the
month
> | and
> |> the previous.
> |>=20
> |> If someone has a clue, something, anything... :)
> |>=20
> | Try
> | ... GROUP BY mois ;
>
> Already tried, not working either.
>
I should have had a closer look:
The WHERE clause is causing the error.
I can't see any quick solution, but what often helped me is
First try to word the query as a view and do the GROUPing then on the
view.
Regards, Christoph
From | Date | Subject | |
---|---|---|---|
Next Message | Achilleus Mantzios | 2003-03-07 15:01:16 | Re: Help on indexing timestamps |
Previous Message | Mathieu Arnold | 2003-03-07 13:29:19 | Re: problem with subselect |