Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2]) by hub.org (8.9.3/8.9.3) with ESMTP id MAA65630 for ; Sat, 23 Oct 1999 12:43:04 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id MAA01539; Sat, 23 Oct 1999 12:42:00 -0400 (EDT) To: guenther@laokoon.IN-Berlin.DE (Christian Guenther) cc: pgsql-sql@postgresql.org Subject: Re: [SQL] sum-function In-reply-to: Your message of Sat, 23 Oct 1999 15:05:19 +0200 (CEST) <199910231305.PAA31741@laokoon.bug.net> Date: Sat, 23 Oct 1999 12:42:00 -0400 Message-ID: <1537.940696920@sss.pgh.pa.us> From: 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