Re: using window-functions to get freshest value - how?

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: using window-functions to get freshest value - how?
Date: 2009-11-20 11:21:11
Message-ID: he5u36$bbh$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 more efficient. 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...

In response to

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2009-11-20 11:49:00 Re: using window-functions to get freshest value - how?
Previous Message Guillaume Cottenceau 2009-11-20 11:17:07 Re: Strange performance degradation