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

Re: using 'count' to show number of dupes

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Andy Harrison <aharrison(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: using 'count' to show number of dupes
Date: 2004-07-12 17:39:00
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
On Mon, 12 Jul 2004, Andy Harrison wrote:

> I'm writing some perl to sendmail maillog reporting.  Since the logs
> are too big to some of the things I want to do, I'm just stuffing it
> to a pgsql db.  I'd like to offload as much of the work onto the db as
> much as possible.
> How can I use count to show rows with the same value in the column?
> col1   col2   col3
> foo1   bar1   baz1
> foo2   bar1   baz2
> foo3   bar2   baz3
> foo4   bar3   baz4
> foo5   bar1   baz5
> foo6   bar2   baz6
> So, what would get pg to show me that col2 has 3 'bar1' values, 2
> 'bar2' values and 1 'bar1' value.

Something like:
select col2, count(*) from table group by col2;

In response to


pgsql-novice by date

Next:From: Mischa SandbergDate: 2004-07-12 17:43:17
Subject: Re: Weird join...
Previous:From: Andy HarrisonDate: 2004-07-12 17:28:40
Subject: using 'count' to show number of dupes

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