Re: having clause question

From: Ian Barwick <barwick(at)gmail(dot)com>
To: Shane Wegner <shane-keyword-pgsql(dot)a1e0d9(at)cm(dot)nu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: having clause question
Date: 2004-10-30 22:36:47
Message-ID: 1d581afe041030153667a867b5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 30 Oct 2004 15:17:16 -0700, Shane Wegner
<shane-keyword-pgsql(dot)a1e0d9(at)cm(dot)nu> wrote:
> Hello,
(...)
> I want to retrieve any last names with more than 1
> occurence in the table. Under MySQL, this query does the
> trick.
> select lastname,count(*) as c from names group by lastname
> having c > 1;
>
> But under PG, it errors out
> ERROR: column "c" does not exist
>
> Is it possible to do a query like this with PostgreSQL?

select lastname,count(*) as c from names group by lastname having count(*) > 1;

HTH

Ian Barwick
barwick(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-10-30 23:12:21 Re: having clause question
Previous Message Ian Barwick 2004-10-30 22:24:43 Re: counting records of schema