X-Original-To: pgsql-php@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 14AA84758F1 for ; Mon, 24 Mar 2003 01:11:25 -0500 (EST) Received: from kumudu.nslk.com (kumudu.nslk.com [64.247.55.254]) by postgresql.org (Postfix) with ESMTP id 59CD6474E42 for ; Mon, 24 Mar 2003 01:11:21 -0500 (EST) Received: from [202.124.170.155] (helo=ibm1) by kumudu.nslk.com with asmtp (Exim 3.36 #1) id 18xLB1-0007rJ-00 for pgsql-php@postgresql.org; Mon, 24 Mar 2003 01:11:20 -0500 Message-ID: <002201c2f1cc$0c58be00$0c00000a@ibm1> Reply-To: "Waruna Geekiyanage" From: "Waruna Geekiyanage" To: References: <1048391256.3e7d2e58a80b9@mail.up.edu.ph> Subject: Re: max and sum function Date: Mon, 24 Mar 2003 12:09:06 +0600 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - kumudu.nslk.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [0 0] X-AntiAbuse: Sender Address Domain - nirmani.com X-Spam-Status: No, hits=-15.9 required=5.0 tests=BAYES_20,ORIGINAL_MESSAGE,REFERENCES 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/38 X-Sequence-Number: 1950 SELECT MAX(aa.res) from ((select sum(col1) as res from table group by id) UNION (select sum(col2) as res from table group by id) UNION (select sum(col3) as res from table group by id)) AS aa; ----- Original Message ----- From: "ryanne cruz" To: Sent: Sunday, 23 March, 2003 9:47 AM Subject: Re: [PHP] max and sum function hi list. 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); then i compare the 3 max values and get the maximum of the 3. is there an easier way to do this? thanks. ryanne ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly