Re: max and sum function

From: "Waruna Geekiyanage" <waruna(at)nirmani(dot)com>
To: <pgsql-php(at)postgresql(dot)org>
Subject: Re: max and sum function
Date: 2003-03-24 06:09:06
Message-ID: 002201c2f1cc$0c58be00$0c00000a@ibm1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php


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" <ryanne(dot)cruz(at)up(dot)edu(dot)ph>
To: <pgsql-php(at)postgresql(dot)org>
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(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Ahmad Sentri 2003-03-25 16:13:27 syntax for option select
Previous Message ryanne cruz 2003-03-23 03:47:36 Re: max and sum function