Re: Use of GROUP BY

From: "Oleg Lebedev" <oleg(dot)lebedev(at)waterford(dot)org>
To: "Mihai Gheorghiu" <tanethq(at)earthlink(dot)net>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Use of GROUP BY
Date: 2002-10-02 20:45:29
Message-ID: 993DBE5B4D02194382EC8DF8554A5273016DB5@postoffice.waterford.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Only attribute in SELECT-clause that are not used in aggregation must be
included in GROUP BY clause. So, if you had smth like:
select field1, sum(amount) from table1 where field1 = 1234 GROUP BY
field1;
You would have to include GROUP BY field 1 as shown above.
In your case, it would just sum up all the amount values in your table.

-----Original Message-----
From: Mihai Gheorghiu [mailto:tanethq(at)earthlink(dot)net]
Sent: Wednesday, October 02, 2002 2:42 PM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] Use of GROUP BY

PG7.2.1 on RH7.3
There is no 1234 value in field1.
select sum(amount) from table1 where field1 = 1234;
sum
-----

(1 row)

select sum(amount) from table1 where field1 = 1234 group by field1; sum
-----
(0 rows)

If GROUP BY should always be used in statements using aggregate
functions, why don't I get an error?

Thank you all.

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2002-10-02 21:21:03 Re: Oracle SGA like feature???
Previous Message Mihai Gheorghiu 2002-10-02 20:42:03 Use of GROUP BY