Re: Using an ALIAS in WHERE clause

Поиск
Список
Период
Сортировка
От Tycho Fruru
Тема Re: Using an ALIAS in WHERE clause
Дата
Msg-id 1038529845.6531.19.camel@bozo.fruru.com
обсуждение исходный текст
Ответ на Using an ALIAS in WHERE clause  ("Ron St.Pierre" <rstpierre@syscor.com>)
Список 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 по дате отправления:

Предыдущее
От: "Ron St.Pierre"
Дата:
Сообщение: Using an ALIAS in WHERE clause
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Using an ALIAS in WHERE clause