From: Fduch the Pravking <fduch@antar.bryansk.ru>
To: Tod McQuillin <devin@spamcop.net>
Cc: Albrecht Berger <berger1517@gmx.ch>
Cc: pgsql <pgsql-sql@postgresql.org>
Subject: Re: count different values in column
Date: Fri, 19 Apr 2002 13:55:02 +0400
Message-ID: <20020419135501.E98305@zombie.antar.bryansk.ru> (raw)
In-Reply-To: <Pine.GSO.4.44.0204190439100.5488-100000@sysadmin>
References: <007901c1e784$e3c21010$a57ba8c0@wxp>
<Pine.GSO.4.44.0204190439100.5488-100000@sysadmin>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: fduch@antar.bryansk.ru, devin@spamcop.net, berger1517@gmx.ch
Subject: Re: count different values in column
In-Reply-To: <20020419135501.E98305@zombie.antar.bryansk.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox