Re: count different values in column

From: Fduch the Pravking <fduch(at)antar(dot)bryansk(dot)ru>
To: Tod McQuillin <devin(at)spamcop(dot)net>
Cc: Albrecht Berger <berger1517(at)gmx(dot)ch>, pgsql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: count different values in column
Date: 2002-04-19 09:55:02
Message-ID: 20020419135501.E98305@zombie.antar.bryansk.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Apr 19, 2002 at 04:40:35AM -0500, Tod McQuillin wrote:
> On Fri, 19 Apr 2002, Albrecht Berger wrote:
>
> > Now I want to count the different values in the column.
> >
> > Resulttable :
> > a
> > ------
> > 10
> > 12
> > 12
> > 12
> > 14
> > 14
> > 15
> >
> > I need the value which is repeated most in the resulttable (in this example
> > 12 ) !
>
> SELECT a, count(a) FROM resulttable GROUP BY a ORDER BY 2 DESC

Note that count on NULL values will always give you 0:

fduch=> INSERT INTO resulttable VALUES (NULL);
INSERT 1702218 1
(repeat some times)

fduch=> SELECT a, count(a) FROM resulttable GROUP BY a ORDER BY 2 DESC;
a | count
----+-------
12 | 3
14 | 2
10 | 1
15 | 1
| 0
(5 rows)

--
Fduch M. Pravking

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gautham S. Rao 2002-04-19 10:00:56 Re: count different values in column
Previous Message Tod McQuillin 2002-04-19 09:40:35 Re: count different values in column