X-Original-To: pgsql-php@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 1007F475F5F for ; Wed, 26 Mar 2003 09:26:24 -0500 (EST) Received: from sabre.velocet.net (sabre.velocet.net [216.138.209.205]) by postgresql.org (Postfix) with ESMTP id 6FD86475F2C for ; Wed, 26 Mar 2003 09:26:22 -0500 (EST) Received: from stark.dyndns.tv (H162.C233.tor.velocet.net [216.138.233.162]) by sabre.velocet.net (Postfix) with ESMTP id 9038C138567; Wed, 26 Mar 2003 09:26:20 -0500 (EST) Received: from localhost ([127.0.0.1] helo=stark.dyndns.tv ident=foobar) by stark.dyndns.tv with smtp (Exim 3.36 #1 (Debian)) id 18yBrA-0001GJ-00; Wed, 26 Mar 2003 09:26:20 -0500 To: "Waruna Geekiyanage" Cc: Subject: Re: max and sum function References: <1048391256.3e7d2e58a80b9@mail.up.edu.ph> <002201c2f1cc$0c58be00$0c00000a@ibm1> In-Reply-To: <002201c2f1cc$0c58be00$0c00000a@ibm1> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 26 Mar 2003 09:26:19 -0500 Message-ID: <87y932kxv8.fsf@stark.dyndns.tv> Lines: 23 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Status: No, hits=-38.8 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_GNUS_UA autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/45 X-Sequence-Number: 1957 "Waruna Geekiyanage" writes: > does anyone here knows of a function that is similar to the sum function but > involves more than one column? for example, i have a table with columns id, > col1, col2 and col3. i want to get the max value from the three columns > gruped > by an id. > > what i came up with is something like this: > > max1=select max(one) from (select sum(col1) as one from table group by id); > max2=select max(two) from (select sum(col2) as two from table group by id); > max3=select max(three) from (select sum(col3) as three from table group by > id); select int4larger(int4larger(max(one),max(two)),max(three)) from table group by id; I'm a bit stumped why it seems I have to use "int4larger" and just "larger" doesn't work like with most functions. There must be a right way to do it without hard coding the datatype. -- greg