How can I find the max from the sum of values? If I try the following I get an error:
Code: Select all
dbadmin=> SELECT c1, SUM(c2) c2_sum FROM test GROUP BY c1 ORDER BY c1, c2_sum;
c1 | c2_sum
----+--------
A | 3
B | 4
C | 4
(3 rows)
Code: Select all
dbadmin=> SELECT MAX(SUM(c2)) c2_sum_max FROM test GROUP BY c1;
ERROR 2135: Aggregate function calls may not be nested
Code: Select all
c1 | c2_sum_max
----+-----------
B | 4
C | 4
Anyone know an esay query that I can use to do this?