pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gerhard Dieringer <DieringG@eba-haus.de>
To: " <Antti Linno" <alligator@all.ee>
Cc: pgsql-sql@postgresql.org
Subject: Antw: GROUP by
Date: Wed, 05 Jul 2000 14:11:22 +0200
Message-ID: <s963420e.005@kopo001> (raw)


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 target list, that are not aggregated.

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

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





Message-ID: <s963420e.005@kopo001>
Permalink:  ../s963420e.005@kopo001/
Also on:    postgresql.org/message-id/s963420e.005@kopo001

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: DieringG@eba-haus.de, Antti Linno" <alligator@all.ee
  Subject: Re: GROUP by
  In-Reply-To: <s963420e.005@kopo001>
  References: <s963420e.005@kopo001>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox