Re: Selecting latest value

Поиск
Список
Период
Сортировка
От Haller Christoph
Тема Re: Selecting latest value
Дата
Msg-id 200109200911.LAA25095@rodos
обсуждение исходный текст
Ответ на Selecting latest value  (Patrik Kudo <kudo@partitur.se>)
Ответы Re: Selecting latest value  (Patrik Kudo <kudo@partitur.se>)
Список pgsql-sql
Try 
create NEWtable (userid text, val integer, ts timestamp);
insert into NEWtable 
select userid, val, max(ts) from table group by userid, val; 

Regards, Christoph 
> 
> 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
> 


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

Предыдущее
От: Haller Christoph
Дата:
Сообщение: Re: Registring a C function in PostgreSQL II
Следующее
От: "David M. Richter"
Дата:
Сообщение: table restruction