| От | Andomar |
|---|---|
| Тема | Re: count distinct and group by |
| Дата | |
| Msg-id | 554B427B.2070509@aule.net обсуждение исходный текст |
| Ответ на | count distinct and group by (Szymon Guz <mabewlun@gmail.com>) |
| Список | pgsql-general |
> And this doesn't: > > select count(distinct id) from bg order by id; > ERROR: column "bg.id <http://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; > Your result set will contain one row with the count of distinct ids. You can't really order 1 row. The error message occurs because your result set has one unnamed column: count(distinct id). You could write the query like: select count(distinct id) as cnt from bg order by cnt; That would be correct SQL, because the column "cnt" now does exist. Kind regards, Andomar
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера