Re: [SQL] count(*) and group by's... - Mailing list pgsql-sql

From David Hartwig
Subject Re: [SQL] count(*) and group by's...
Date
Msg-id 362CCAB8.480ECB64@insightdist.com
Whole thread Raw
In response to count(*) and group by's...  (Howie <caffeine@toodarkpark.org>)
List pgsql-sql
SELECT types.type, hosts.hostname, types.batch, count(codes.code)
        FROM hosts,types,codes
WHERE hosts.client=3 AND
    hosts.client=types.client AND
    types.type=codes.type
GROUP BY types.type, hosts.hostname, types.batch
--                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
ORDER BY types.batch;

-- All columns in the target (projection) must be either an aggregate
function or grouped by


Howie wrote:

> I give up.  I'm trying to get a count of one table joining with another,
> but Postgres ( 6.3.2 ) doesnt like me.
>
> SELECT types.type,hosts.hostname,types.batch,count(codes.code) FROM
> hosts,types,codes WHERE hosts.client=3 AND hosts.client=types.client AND
> types.type=codes.type GROUP BY types.type ORDER BY types.batch;
>
> returns:
>
> ERROR:  parser: illegal use of aggregates or non-group column in target
> list
>
> in fact, trying to do any join across types and codes results in an
> illegal use/non-group column.  types.type is primary,
> codes.type+codes.code is primary.
>
> ---
> Howie <caffeine@toodarkpark.org>   URL: http://www.toodarkpark.org
>         "Oh my god, they killed init!  YOU BASTARDS!"




pgsql-sql by date:

Previous
From: Paul Friberg CEO - ISTI
Date:
Subject: PostgreSQL COPY command
Next
From: Mark Wilson
Date:
Subject: Large Object Interface