Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-general by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group