Re: sub query

Поиск
Список
Период
Сортировка
От Christoph Haller
Тема Re: sub query
Дата
Msg-id 3F681D6F.1E82CAFC@rodos.fzk.de
обсуждение исходный текст
Ответ на sub query  ("Martin Kuria" <martinkuria@hotmail.com>)
Список pgsql-sql
> Hi I have this problem, when I try to run this query:
>
> SELECT MAX(d), host_position FROM (SELECT host_position,
> COUNT(host_position) as d FROM sss_host GROUP BY host_position) as e;
>
> am getting and ERROR: Attribute e.host_position must be GROUPed or
used in
> an aggregate function.
>
> Please to advice what could be the problem and how can I rewrite it to
work
> thanks in advance.
>
As the error message says: e.host_position must be GROUPed

so (supposing you want a one row result showing the maximum count)

SELECT MAX(e.d), e.host_position FROM (SELECT host_position,
COUNT(host_position) as d FROM sss_host GROUP BY host_position) as e
GROUP BY e.host_position ORDER BY 1 LIMIT 1;

should match your intentions.

Regards, Christoph




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

Предыдущее
От: "Martin Kuria"
Дата:
Сообщение: sub query
Следующее
От: Christoph Haller
Дата:
Сообщение: Re: sub query