Re: [GENERAL] HAVING QUESTION

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: Alexander Barkov <bar(at)izhcom(dot)ru>
Cc: "'pgsql-general(at)hub(dot)org'" <pgsql-general(at)hub(dot)org>
Subject: Re: [GENERAL] HAVING QUESTION
Date: 1999-11-03 18:17:48
Message-ID: 199911031817.NAA25326@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

[Charset koi8-r unsupported, filtering to ASCII...]
>
> Hi!
>
>
> How can I refer the calculated field in HAVING clause.
>
> This work in MySQL:
>
> SELECT some_expression as field1, ...
> FROM tablename
> GROUP BY ...
> HAVING field1>0;
>
> PostgreSQL gives error "Attribute 'field1' not found".

Worked here in development tree:

select state as test, count(*)
from friends
group by test
having count(*) > 1\g

test|count
----+-----
MA | 2
NJ | 2
(2 rows)

I think your problem is that field1 is not an aggregate or if it is, you
may need to repeat the aggregate in the having.

--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Simon Drabble 1999-11-03 18:39:53 Dynamic update
Previous Message Andrew Perrin - Demography 1999-11-03 17:24:54 RE: [GENERAL] plpgsql problem: relocation error