Re: [GENERAL] HAVING QUESTION - Mailing list pgsql-general

From Bruce Momjian
Subject Re: [GENERAL] HAVING QUESTION
Date
Msg-id 199911031817.NAA25326@candle.pha.pa.us
Whole thread Raw
In response to HAVING QUESTION  (Alexander Barkov <bar@izhcom.ru>)
List 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@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

pgsql-general by date:

Previous
From: Alexander Barkov
Date:
Subject: ANNOUNCE UdmSearch-2.1.6
Next
From: Simon Drabble
Date:
Subject: Dynamic update