Re: using window-functions to get freshest value - how? - Mailing list pgsql-general

From Thomas Kellerer
Subject Re: using window-functions to get freshest value - how?
Date
Msg-id he5u36$bbh$1@ger.gmane.org
Whole thread Raw
In response to Re: using window-functions to get freshest value - how?  ("Massa, Harald Armin" <chef@ghum.de>)
List pgsql-general
Massa, Harald Armin, 20.11.2009 11:31:
> no, that does not work:
> "id_bf";"wert";"max"
> 98;"blue";"2009-11-10 00:00:00"
> 98;"red";"2009-11-10 00:00:00"
>
> result is: I get the date of the youngest value.
>
> My expected result is:
>
> 98;"red"
>
> (that is, the entry of "wert" that is youngest)
>
Sorry then I misunderstood your requirement

I don't think windowing functions are the best choice here.

I'd probably use something like:

SELECT r1.id_bf, r1.wert
FROM rfmitzeit r1
WHERE letztespeicherung =
      (SELECT max(letztespeicherung)
       FROM rfmitzeit r2
       WHERE r2.id_bf = r1.id_bf)

Not really different to your solution, but I think it's easier to read (personal taste!) but it also could be slightly
moreefficient. But most probably the optimizer is smart enough... 

Regards
Thomas

P.S.: could you please turn off the HTML format for your mails.
Especially the SQL statements are very hard to read...

pgsql-general by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: using window-functions to get freshest value - how?
Next
From: "A. Kretschmer"
Date:
Subject: Re: using window-functions to get freshest value - how?