Re: Using an ALIAS in WHERE clause - Mailing list pgsql-general

From Tycho Fruru
Subject Re: Using an ALIAS in WHERE clause
Date
Msg-id 1038529845.6531.19.camel@bozo.fruru.com
Whole thread Raw
In response to Using an ALIAS in WHERE clause  ("Ron St.Pierre" <rstpierre@syscor.com>)
List pgsql-general
On Fri, 2002-11-29 at 01:17, Ron St.Pierre wrote:
> I'm using a query with similar functionality to the following:
>
>   SELECT  id,
>   sum(hours) AS totalhours
>   FROM mytable
>   WHERE totalhours > 50;
>
> I get the following error:
>   Attribute 'totalhours' not found.
>
> Am I not allowed to use an alias here? If not, how can I get my desired
> output?

select id, sum(hours) as totalhours
from mytable
group by id
having totalhours > 50

'where' is for tuple selection criteria
'having' is for group selection criteria
i suppose you want to have the total number of hours per id (therefore
we need to group by id.

Does this help ?
Tycho




pgsql-general by date:

Previous
From: "Ron St.Pierre"
Date:
Subject: Using an ALIAS in WHERE clause
Next
From: Tom Lane
Date:
Subject: Re: Using an ALIAS in WHERE clause