Re: using 'count' to show number of dupes

From: "Loftis, Charles E" <charles(dot)loftis(at)eds(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: using 'count' to show number of dupes
Date: 2004-07-12 17:50:39
Message-ID: 25DC89BACF65D549BA045B806348C65E045DC6FF@ushem201.exse01.exch.eds.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Write a queries like this...

SELECT col1, count(col1) as count_col1
FROM <table>
GROUP BY col1

-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of Andy Harrison
Sent: Monday, July 12, 2004 1:29 PM
To: pgsql-novice(at)postgresql(dot)org
Subject: [NOVICE] using 'count' to show number of dupes

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.

--
Andy Harrison

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Browse pgsql-novice by date

  From Date Subject
Next Message Andy Harrison 2004-07-12 18:02:14 Re: using 'count' to show number of dupes
Previous Message Mischa Sandberg 2004-07-12 17:43:17 Re: Weird join...