Re: writing a MIN(RECORD) aggregate - Mailing list pgsql-hackers

From Decibel!
Subject Re: writing a MIN(RECORD) aggregate
Date
Msg-id F4A45BEA-1FF3-48A3-A055-6EE0C3A4EED0@decibel.org
Whole thread Raw
In response to Re: writing a MIN(RECORD) aggregate  (Sam Mason <sam@samason.me.uk>)
List pgsql-hackers
On Mar 25, 2008, at 11:33 AM, Sam Mason wrote:
> On Mon, Mar 24, 2008 at 05:27:04PM -0500, Decibel! wrote:
>> On Mar 20, 2008, at 2:23 PM, Sam Mason wrote:
>>>  SELECT i, (MIN((j,k))).k
>>>  FROM tbl
>>>  GROUP BY i;
>>
>> How is that any better than SELECT i, min(k) FROM tbl GROUP BY i ?
>
> Because I want the value of k associated with the minimum value of j.


Ahh, makes sense. FWIW...

SELECT i, (SELECT k FROM ... WHERE i = i.i ORDER BY j LIMIT 1)    FROM (SELECT DISTINCT i FROM ...) i
;

If you needed more than just k, I think there's a way to do that in  
the FROM clause, too.
-- 
Decibel!, aka Jim C. Nasby, Database Architect  decibel@decibel.org
Give your computer some brain candy! www.distributed.net Team #1828



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [GENERAL] ANALYZE getting dead tuple count hopelessly wrong
Next
From: "Marc G. Fournier"
Date:
Subject: Re: Several tags around PostgreSQL 7.1 broken