Обсуждение: Re: [SQL] sum-function

Поиск
Список
Период
Сортировка

Re: [SQL] sum-function

От
Tom Lane
Дата:
guenther@laokoon.IN-Berlin.DE (Christian Guenther) writes:
> SELECT (sum(case when dict.word = 'museum' then 1 else 0 end)) as qu, 
> dict.url_id FROM dict, url
>              WHERE url.rec_id = dict.url_id
>                    AND url.url LIKE '%%'
>                    AND dict.word in ('museum')
>              GROUP BY dict.url_id
>         having qu > 0
> The Problem is qu, I cannot use it for the having.

Neither WHERE nor HAVING pay any attention to column labels; they
work on original attributes.  (Only GROUP BY and ORDER BY accept
column labels as substitutes for real expressions.)  You'll need
to repeat the sum() expression in HAVING, I'm afraid.
        regards, tom lane