From: | Erik Jones <erik(at)myemma(dot)com> |
---|---|
To: | Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com> |
Cc: | "Josh Williams" <joshwilliams(at)ij(dot)net>, emilu(at)encs(dot)concordia(dot)ca, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Get the max(value1, value2, value3) from a table |
Date: | 2008-01-07 23:16:58 |
Message-ID: | 53C367DF-24B3-425C-9EE7-BBA7336D3A89@myemma.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Jan 7, 2008, at 4:43 PM, Scott Marlowe wrote:
> On Jan 7, 2008 4:38 PM, Josh Williams <joshwilliams(at)ij(dot)net> wrote:
>> On Mon, 2008-01-07 at 17:03 -0500, Emi Lu wrote:
>>> select ?max?(col1, col2, col3) as result;
>>> will return
>>>
>>> result
>>> -------
>>> 5
>>> 8
>>> 12
>>>
>>> (3 rows)
>>
>> 8.1 (I believe?) introduced GREATEST(), which does precisely what
>> you're
>> looking for.
>
> How would greatest give him three rows like that? Maybe I'm
> misunderstanding what the OP was asking for...
His test data was:
col1 col2 col3
----------------------
1 5 2
8 1 3
12 1 1
So, SELECT test(col1, col2, col3);
returning
test
-----
5
8
12
Is giving the max of the three columns for each row.
Erik Jones
DBA | Emma®
erik(at)myemma(dot)com
800.595.4401 or 615.292.5888
615.292.0777 (fax)
Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com
From | Date | Subject | |
---|---|---|---|
Next Message | Jamie Tufnell | 2008-01-08 14:24:22 | How to keep at-most N rows per group? periodic DELETEs or constraints or..? |
Previous Message | Scott Marlowe | 2008-01-07 23:16:21 | Re: Get the max(value1, value2, value3) from a table |