From: | Greg Stark <gsstark(at)mit(dot)edu> |
---|---|
To: | "Waruna Geekiyanage" <waruna(at)nirmani(dot)com> |
Cc: | <pgsql-php(at)postgresql(dot)org> |
Subject: | Re: max and sum function |
Date: | 2003-03-26 14:26:19 |
Message-ID: | 87y932kxv8.fsf@stark.dyndns.tv |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-php |
"Waruna Geekiyanage" <waruna(at)nirmani(dot)com> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Ray Hunter | 2003-03-26 16:11:43 | Re: make form list with option select |
Previous Message | apz | 2003-03-26 06:59:26 | Re: make form list with option select |