Re: [SQL] sum-function - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] sum-function
Date
Msg-id 1537.940696920@sss.pgh.pa.us
Whole thread Raw
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: [SQL] Can VACUUM, but cannot do VACUUM ANALYZE
Next
From: "Albert REINER"
Date:
Subject: Re: [SQL] Can VACUUM, but cannot do VACUUM ANALYZE