Re: Picking out the most recent row using a time stamp column

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/24/2011 06:20 PM, Josh Berkus wrote:

SELECT id_key, time_stamp, value
FROM (
	SELECT id_key, time_stamp, value,
		row_number()
		OVER ( PARTITION BY id_key
			ORDER BY time_stamp DESC)
  		as ranking
	FROM thetable
       ) as filtered_table
WHERE ranking = 1

Why did you use row_number instead of rank?

I am now curious how the speed compares though. I still think the DISTINCT ON will be faster, but it would be a great surprise.

--
Shaun Thomas
OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604
312-676-8870
sthomas@xxxxxxxxx

______________________________________________

See  http://www.peak6.com/email_disclaimer.php
for terms and conditions related to this email

--
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux