From: | Javier Dussaillant <ashkar(at)vrweb(dot)cl> |
---|---|
To: | Francisco Reyes <lists(at)natserv(dot)com>, pgsql General List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Select .. Having vs computer fields |
Date: | 2001-12-12 18:33:01 |
Message-ID: | 5.0.2.1.2.20011212152736.024335a0@192.168.0.254 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
At 12:54 PM 12/12/2001 -0500, Francisco Reyes wrote:
>Can use use computed fields on the "having" part of select?
>I have tried:
>select a,b, count(*) as dups_count from some_table having dups_count > 1;
>
>and it gives me the error "Attribute 'dups_count' not found"
You have to GROUP BY in order to use HAVING. For example:
SELECT a,b, count(*) as dups_count FROM some_table GROUP BY a,b HAVING
dups_count > 1;
You should GROUP your rows by all the columns that are not count() or other
aggregate function (like max(), min(), sum(), etc).
>---------------------------(end of broadcast)---------------------------
>TIP 3: if posting/reading through Usenet, please send an appropriate
>subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
>message can get through to the mailing list cleanly
Javier Dussaillant G.
ashkar(at)vrweb(dot)cl
Departamento de Desarrollo VRWEB ltda.
http://www.vrweb.cl
From | Date | Subject | |
---|---|---|---|
Next Message | Geoffrey J. Gowey | 2001-12-12 19:51:50 | returning multiple results with stored procedures |
Previous Message | Dado Feigenblatt | 2001-12-12 18:27:37 | Re: User rights across databases |