Re: Use of GROUP BY - Mailing list pgsql-general

From Oleg Lebedev
Subject Re: Use of GROUP BY
Date
Msg-id 993DBE5B4D02194382EC8DF8554A5273016DB5@postoffice.waterford.org
Whole thread Raw
In response to Use of GROUP BY  ("Mihai Gheorghiu" <tanethq@earthlink.net>)
List 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@earthlink.net]
Sent: Wednesday, October 02, 2002 2:42 PM
To: pgsql-general@postgresql.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

pgsql-general by date:

Previous
From: "Mihai Gheorghiu"
Date:
Subject: Use of GROUP BY
Next
From: Bruce Momjian
Date:
Subject: Re: Oracle SGA like feature???