Re: count different values in column - Mailing list pgsql-sql

From Fduch the Pravking
Subject Re: count different values in column
Date
Msg-id 20020419135501.E98305@zombie.antar.bryansk.ru
Whole thread Raw
In response to Re: count different values in column  (Tod McQuillin <devin@spamcop.net>)
List 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 |     314 |     210 |     115 |     1   |     0
(5 rows)

-- 
Fduch M. Pravking


pgsql-sql by date:

Previous
From: Christoph Haller
Date:
Subject: Re: count different values in column
Next
From: Rajesh Kumar Mallah
Date:
Subject: how to get index scan at work?