Re: count different values in column

Поиск
Список
Период
Сортировка
От Fduch the Pravking
Тема Re: count different values in column
Дата
Msg-id 20020419135501.E98305@zombie.antar.bryansk.ru
обсуждение исходный текст
Ответ на Re: count different values in column  (Tod McQuillin <devin@spamcop.net>)
Список 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 по дате отправления:

Предыдущее
От: Christoph Haller
Дата:
Сообщение: Re: count different values in column
Следующее
От: Rajesh Kumar Mallah
Дата:
Сообщение: how to get index scan at work?