Search Postgresql Archives

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

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

 



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...

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux