How to get most frequent and least frequent values in a column?

From: Matthew Wilson <matt(at)overlook(dot)homelinux(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: How to get most frequent and least frequent values in a column?
Date: 2004-09-20 14:27:41
Message-ID: slrncktq6q.icu.matt@mwilson.umlcoop.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'm a noob SQL user, crossing over from SAS. I have a table with about
200k rows and one of the columns is empssn, which holds the employee
social security number. The same empssn may appear in lots of different
rows. I want to get a list of the 40 top empssns, sorted by the number
of times they appear in the table. I also want a list of the very rarest
empssns (ones that only appear once or twice).

Can anyone help me with this? BTW, this isn't a homework problem.

TIA.

Matt

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-09-20 14:56:47 Re: Weird behavior with selects and composite data types
Previous Message Tom Lane 2004-09-20 14:25:18 Re: order of row processing affects updates