Use of GROUP BY
Use of GROUP BY
От:
"Mihai Gheorghiu" <tanethq@earthlink.net>
Дата:
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.
Re: Use of GROUP BY
От:
"Oleg Lebedev" <oleg.lebedev@waterford.org>
Дата:
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