Antw: GROUP by

Поиск
Список
Период
Сортировка
От Gerhard Dieringer
Тема Antw: GROUP by
Дата
Msg-id s963420e.005@kopo001
обсуждение исходный текст
Список pgsql-sql
Antti Linno <alligator@all.ee> wrote:

> I have table job, and I want to select data from it, grouping by
> workgroups. When I use 
>  select id,name from job where workgroup='top leaders' AND ...  group by
> workgroup;
> When I want to group, I get 
> ERROR:  Illegal use of aggregates or non-group column in target list
> I'm confused, why does query work only with sum,min etc. alone in
> select.
> 
> Antti

You can use GROUP BY only in conjunction with aggregat functions. Then you have to gruop by all attributes in the
targetlist, that are not aggregated.
 

Example:
select id,name, workgroup, count(*) 
from job 
where workgroup='top leaders' AND ...  
group by id,name,workgroup;

-------------
Gerhard




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

Предыдущее
От: Antti Linno
Дата:
Сообщение: Group BY ...(cont.)
Следующее
От: Jesus Aneiros
Дата:
Сообщение: Re: GROUP by