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

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: using window-functions to get freshest value - how?
Дата
Msg-id he5u36$bbh$1@ger.gmane.org
обсуждение исходный текст
Ответ на Re: using window-functions to get freshest value - how?  ("Massa, Harald Armin" <chef@ghum.de>)
Список 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 по дате отправления:

Предыдущее
От: hubert depesz lubaczewski
Дата:
Сообщение: Re: using window-functions to get freshest value - how?
Следующее
От: "A. Kretschmer"
Дата:
Сообщение: Re: using window-functions to get freshest value - how?