count distinct and group by

Поиск
Список
Период
Сортировка
От Szymon Guz
Тема count distinct and group by
Дата
Msg-id CAFjNrYtrTMFmRVrz=PyWkm-SBQQq28DvTzmsaYuVP-bqjPERDQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: count distinct and group by
Re: count distinct and group by
Re: count distinct and group by
Список pgsql-general
Hi,
I'm not sure why there is a reason for such behaviour.

For this table:

create table bg(id serial primary key, t text);

This works:

select count(id) from bg;

This works:

select count(distinct id) from bg;

And this doesn't:

select count(distinct id) from bg order by id;
ERROR:  column "bg.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: select count(distinct id) from bg order by id;

thanks,
Szymon

В списке pgsql-general по дате отправления:

Предыдущее
От: Tim Clarke
Дата:
Сообщение: Re: detached query?
Следующее
От: Magnus Hagander
Дата:
Сообщение: Re: count distinct and group by