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 10:23:07
Message-ID: he5qma$gi$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Massa, Harald Armin, 20.11.2009 11:07:
> I have a table
>
> CREATE TABLE rfmitzeit
> (
> id_rf inet NOT NULL,
> id_bf integer,
> wert text,
> letztespeicherung timestamp without time zone
> CONSTRAINT repofeld_id_rf PRIMARY KEY (id_rf),
> );
>
>
> where for one id_bf there are stored mutliple values ("wert") at
> multiple dates:
>
> id_bf, wert, letztespeicherung:
> 98, 'blue', 2009-11-09
> 98, 'red', 2009-11-10
>
>
> now I have a select to get the "youngest value" for every id_bf:

Not tested:

SELECT id_bf,
wert,
max(letztespeicherung) over (partition by id_bf)
FROM rfmitzeit

Regards
Thomas

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2009-11-20 10:23:22 Re: Strange performance degradation
Previous Message Tino Wildenhain 2009-11-20 10:19:37 Re: Allowing for longer table names (>64 characters)