Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B0985B5DBCA for ; Thu, 12 May 2011 19:19:00 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 27401-07-2 for ; Thu, 12 May 2011 22:18:53 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pz0-f46.google.com (mail-pz0-f46.google.com [209.85.210.46]) by mail.postgresql.org (Postfix) with ESMTP id 66A1BB5DBCF for ; Thu, 12 May 2011 19:18:46 -0300 (ADT) Received: by pzk9 with SMTP id 9so909716pzk.19 for ; Thu, 12 May 2011 15:18:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.34.7 with SMTP id v7mr995347pbi.371.1305238726442; Thu, 12 May 2011 15:18:46 -0700 (PDT) Received: by 10.68.48.68 with HTTP; Thu, 12 May 2011 15:18:46 -0700 (PDT) X-Originating-IP: [66.215.95.51] In-Reply-To: References: Date: Thu, 12 May 2011 15:18:46 -0700 Message-ID: Subject: Re: ordering by date for each ID From: Samuel Gendler To: Thomas Kellerer Cc: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary=bcaec520f295a2ff3504a31b921e X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 201105/87 X-Sequence-Number: 35371 --bcaec520f295a2ff3504a31b921e Content-Type: text/plain; charset=ISO-8859-1 On Thu, May 12, 2011 at 1:45 PM, Thomas Kellerer wrote: > Nguyen,Diep T wrote on 12.05.2011 03:59: > >> >> Any help would be appreciated. >> > > SELECT id, > date, > score_count, > row_number() over (partition by id order by date desc) as order_value > FROM your_table > > > Or the more general answer to your question is this: http://www.postgresql.org/docs/8.4/interactive/functions-window.html There's lots of neat things you can do with window functions. --sam --bcaec520f295a2ff3504a31b921e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Thu, May 12, 2011 at 1:45 PM, Thomas = Kellerer <spam_e= ater@gmx.net> wrote:
Nguyen,Diep T wrote on 12.05.2011 03:59:

Any help would be appreciated.

SELECT id,
=A0 =A0 =A0 date,
=A0 =A0 =A0 score_count,
=A0 =A0 =A0 row_number() over (partition by id order by date desc) as orde= r_value
FROM your_table



Or the more general answer= to your question is this:=A0http://www.postgresql.org/docs/8.4/inter= active/functions-window.html =A0There's lots of neat things you can= do with window functions.

--sam


--bcaec520f295a2ff3504a31b921e--