pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Joseph Shraibman <jks@selectacast.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: WHERE on an alias
Date: Fri, 24 Aug 2001 12:58:40 -0700
Message-ID: <web-107962@davinci.ethosmedia.com> (raw)
In-Reply-To: <3B8698E7.4080106@selectacast.net>

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@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco



view thread (9+ messages)  latest in thread

Message-ID: <web-107962@davinci.ethosmedia.com>
Permalink:  ../web-107962@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-107962@davinci.ethosmedia.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, jks@selectacast.net
  Subject: Re: WHERE on an alias
  In-Reply-To: <web-107962@davinci.ethosmedia.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