Re: Selecting latest value

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: Selecting latest value
Дата
Msg-id Pine.BSF.4.21.0109200746550.74020-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на Re: Selecting latest value  (Patrik Kudo <kudo@partitur.se>)
Список pgsql-sql
On Thu, 20 Sep 2001, Patrik Kudo wrote:

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

Maybe something like: (assuming that ts is unique within each userid,
otherwise what does latest mean?  I haven't tried this, so it probably
doesn't parse, but...)

select userid, val from table where ts=(select max(ts) from table t wheret.userid=table.userid group by userid);



В списке pgsql-sql по дате отправления:

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: table restruct...
Следующее
От: Patrik Kudo
Дата:
Сообщение: Re: Selecting latest value