From: | Thomas Kellerer <spam_eater(at)gmx(dot)net> |
---|---|
To: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: Sorted group by |
Date: | 2010-08-10 16:22:27 |
Message-ID: | i3rubv$boj$1@dough.gmane.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Matthew Wakeling wrote on 10.08.2010 18:03:
> On Tue, 10 Aug 2010, Thomas Kellerer wrote:
>> No. It's built in (8.4) and it's called Windowing functions:
>> http://www.postgresql.org/docs/8.4/static/tutorial-window.html
>> http://www.postgresql.org/docs/8.4/static/functions-window.html
>>
>> SELECT group, last_value(value) over(ORDER BY number)
>> FROM table
>
> I may be mistaken, but as I understand it, a windowing function doesn't
> reduce the number of rows in the results?
Yes you are right, a bit too quick on my side ;)
But this might be what you are after then:
select group_, value_
from (
select group_, value_, number_, row_number() over (partition by group_ order by value_ desc) as row_num
from numbers
) t
where row_num = 1
order by group_ desc
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Smith | 2010-08-10 16:27:20 | Re: Completely un-tuned Postgresql benchmark results: SSD vs desktop HDD |
Previous Message | Greg Smith | 2010-08-10 16:21:20 | Re: Completely un-tuned Postgresql benchmark results: SSD vs desktop HDD |