Re: [GENERAL] Re: Need help with what I think is likely a simple query - for each distinct val, return only one record with the most recent date.

2011-09-13 Thread Vincent de Phily
On Monday 12 September 2011 22:51:54 Reid Thompson wrote: test=# select distinct on (val1) val1, val2, val3 from (SELECT max(val3) OVER (PARTITION BY val1), * FROM sampledata) as sq where val3 = max order by val1; Other things I've tried (was limited to PG8.3 so no OVER (PARTITION...)

Re: [GENERAL] Re: Need help with what I think is likely a simple query - for each distinct val, return only one record with the most recent date.

2011-09-13 Thread Hannes Erven
Reid, where any one of these 3 11 2011-01-01 11 2011-01-01 13 2011-01-01 or any one of these 2 31 2011-01-05 32 2011-01-05 are suitable for val = 1, val = 3 respectively. Can you please describe in words what you are trying to

Re: [GENERAL] Re: Need help with what I think is likely a simple query - for each distinct val, return only one record with the most recent date.

2011-09-13 Thread Reid Thompson
On Tue, 2011-09-13 at 16:39 +0200, Hannes Erven wrote: Reid, where any one of these 3 11 2011-01-01 11 2011-01-01 13 2011-01-01 or any one of these 2 31 2011-01-05 32 2011-01-05 are suitable for val = 1, val = 3

Re: [GENERAL] Re: Need help with what I think is likely a simple query - for each distinct val, return only one record with the most recent date.

2011-09-13 Thread Eduardo Piombino
I'm sorry Reid, driving back home I realized that the previous query I suggested didn't do what I was expecting, cause it would compute all of val2 for each val1, even if they belonged to another group (not for a particular val1/date pair), or in other words, to another date. I've considered this

[GENERAL] Re: Need help with what I think is likely a simple query - for each distinct val, return only one record with the most recent date.

2011-09-12 Thread Reid Thompson
On 9/12/2011 9:54 PM, Reid Thompson wrote: Ack -- i flubbed the subject and sample. The sample data should be val val2date 11 2011-01-01 22 2011-01-02 33 2011-01-03 41 2011-01-04 52 2011-01-05 53 2011-01-01 41 2011-01-02

[GENERAL] Re: Need help with what I think is likely a simple query - for each distinct val, return only one record with the most recent date.

2011-09-12 Thread Reid Thompson
Ack -- i flubbed the subject and sample. The sample data should be val val2date 11 2011-01-01 22 2011-01-02 33 2011-01-03 41 2011-01-04 52 2011-01-05 53 2011-01-01 41 2011-01-02 62 2011-01-03 43