Illegal use of aggregates or non-group column in target list

From: "G(dot) Anthony Reina" <reina(at)nsi(dot)edu>
To: "pgsql-general(at)hub(dot)org" <pgsql-general(at)hub(dot)org>
Subject: Illegal use of aggregates or non-group column in target list
Date: 2000-03-03 18:14:58
Message-ID: 38C00122.F382048C@nsi.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'd like to return an average for one item in my database grouped by
another item. For example,

The table looks like this:
=================
CREATE TABLE data_table (
subject text,
arm char,
target int4, -- end of primary
key
reaction_time float4
);
CREATE UNIQUE INDEX pkdata_table ON data_table (subject, arm, target);

The command I'd like to use is something like:
================================
select target, avg(reaction_time) from data_table;

and I'd like this command to return:

target | avg
=============
1 | 301.3
2 | 311.45
3 | 299.1
4 | 300.8

However, this statement just gives me the error: Illegal use of
aggregates or non-group column in target list.

So apparently I can only return either one or the other but not the two
together. Is there a way to get the output I want in SQL?

Thanks.
-Tony

Responses

Browse pgsql-general by date

  From Date Subject
Next Message G. Anthony Reina 2000-03-03 18:53:41 Re: [GENERAL] Illegal use of aggregates or non-group column in target list
Previous Message kaiq 2000-03-03 17:42:07 PG is great and m$sucks