From: | "Josh Berkus" <josh(at)agliodbs(dot)com> |
---|---|
To: | Joseph Shraibman <jks(at)selectacast(dot)net> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: WHERE on an alias |
Date: | 2001-08-24 19:58:40 |
Message-ID: | web-107962@davinci.ethosmedia.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Joseph,
> playpen=# select a, sum(b) as dsum from taba where dsum > 5 group
> by(a);
> ERROR: Attribute 'dsum' not found
>
> Why can we GROUP BY on an alias but not do a WHERE on an alias? I
> have a subselect that
> explain shows is being run twice if I have to put it in the WHERE
> clause.
Ah, but you are not trying to do a WHERE on an alias ... you are trying
to do a WHERE on an *aggregate*, which is a different thing. Consult
your favorite SQL manual; the construction you want is:
SELECT a, sum(b) as dsum
FROM taba
GROUP BY a
HAVING dsum > 5;
-Josh Berkus
______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
From | Date | Subject | |
---|---|---|---|
Next Message | Joseph Shraibman | 2001-08-24 20:18:50 | Re: WHERE on an alias |
Previous Message | Josh Berkus | 2001-08-24 19:56:16 | Indexing and performance |