Received: from zombie.antar.bryansk.ru (zombie.antar.bryansk.ru [195.239.214.68]) by postgresql.org (Postfix) with ESMTP id D14FF47510B for ; Fri, 19 Apr 2002 05:54:05 -0400 (EDT) Received: (from fduch@localhost) by zombie.antar.bryansk.ru (8.11.3/8.11.3) id g3J9t2811772; Fri, 19 Apr 2002 13:55:02 +0400 (MSD) (envelope-from fduch) Date: Fri, 19 Apr 2002 13:55:02 +0400 From: Fduch the Pravking To: Tod McQuillin Cc: Albrecht Berger , pgsql Subject: Re: count different values in column Message-ID: <20020419135501.E98305@zombie.antar.bryansk.ru> References: <007901c1e784$e3c21010$a57ba8c0@wxp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from devin@spamcop.net on Fri, Apr 19, 2002 at 04:40:35AM -0500 X-Archive-Number: 200204/242 X-Sequence-Number: 7506 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