Re: Selecting latest value II

From: Haller Christoph <ch(at)rodos(dot)fzk(dot)de>
To: kudo(at)partitur(dot)se (Patrik Kudo)
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Selecting latest value II
Date: 2001-09-20 16:02:32
Message-ID: 200109201402.QAA25852@rodos
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

What do you mean by
"the latest val for each userid"
I cannot understand how a value of type integer
can have a attribute like "latest".
Sorry, but I need at least a bit more information.
Regards, Christoph
>
> On Thu, 20 Sep 2001, Haller Christoph wrote:
>
> > Try
> > create NEWtable (userid text, val integer, ts timestamp);
> > insert into NEWtable
> > select userid, val, max(ts) from table group by userid, val;
>
> That won't work. That will give me multiple userid-val combinations. Sure,
> the userid-val combinations will be unique, but I want unique userids
> with only the latest val for each userid.
>
> /Patrik Kudo
>
> > >
> > > Hi,
> > >
> > > I have a table which basically looks like this:
> > >
> > > create table (userid text, val integer, ts timestamp);
> > >
> > > This table holds multiple values for users, timestamped for history
> > > reasons.
> > >
> > > Now I need to fetch the latest val for each userid to insert into a new
> > > table (with about the same schema, except for uniqueness on userid).
> > > I belive this should be a trivial task, but I'm experience total lack of
> > > insight here...
> > >
> > > Comments?
> > >
> > > /Patrik Kudo
> > >
> >
>
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Thurstan R. McDougle 2001-09-20 16:30:46 Re: Selecting latest value II
Previous Message Chris Ruprecht 2001-09-20 15:25:58 Re: Selecting latest value II