From: | Kris Kewley <kris(dot)kewley(at)gmail(dot)com> |
---|---|
To: | Rikard Bosnjakovic <rikard(dot)bosnjakovic(at)gmail(dot)com> |
Cc: | "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Column aliases for GROUP BY and HAVING |
Date: | 2009-11-26 00:47:06 |
Message-ID: | 808D1FF4-C75A-4713-9C43-4979C9367CC1@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
I think because you are not selecting the column you are referring to.
Try:
HAVING SUM(y)>3
Kris
On 25-Nov-09, at 14:20, Rikard Bosnjakovic
<rikard(dot)bosnjakovic(at)gmail(dot)com> wrote:
> (Postgres version 8.2.4)
>
> Trying to understand GROUP BY, I'm reading on
> <http://www.postgresql.org/docs/8.4/interactive/queries-table-expressions.html
> >.
> Consider this query:
>
> => select x, sum(y) from test1 group by x order by x;
> x | sum
> ---+-----
> a | 4
> b | 5
> c | 2
> (3 rows)
>
> I understand what's happening here, all is fine. So I play with
> HAVING:
>
> => select x, sum(y) from test1 group by x having sum(y)>3 order by x;
> x | sum
> ---+-----
> a | 4
> b | 5
> (2 rows)
>
>
> But this confuses me:
>
> => select x, sum(y) as foo from test1 group by x having foo>3 order
> by x;
> ERROR: column "foo" does not exist
> LINE 1: ...ect x, sum(y) as foo from test1 group by x having foo>3
> orde...
>
> Why isn't it possible to refer to a column alias in HAVING?
>
>
> --
> - Rikard
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
From | Date | Subject | |
---|---|---|---|
Next Message | Rikard Bosnjakovic | 2009-11-26 01:14:04 | Re: Column aliases for GROUP BY and HAVING |
Previous Message | Joshua Tolley | 2009-11-25 22:34:12 | Re: Anonymous code blocks |