Select most recent record?
| От | Marc Sherman |
|---|---|
| Тема | Select most recent record? |
| Дата | |
| Msg-id | CGEPKMKAIFJINAOACFFEOEJDCGAA.msherman@projectile.ca обсуждение исходный текст |
| Ответы |
Re: Select most recent record?
RE: Select most recent record? |
| Список | pgsql-sql |
Hi, I was hoping I could get some help with a select statement. I have a log table with three columns: id int4, timestamp datetime, value int4. For any given ID, there will be a large number of rows, with different timestamps and values. I'd like to select the newest (max(timestamp)) row for each id, before a given cutoff date; is this possible? The best I've been able to come up with is the rather ugly (and very slow): select * from log as l1 where timestamp in(select max(timestamp) from log where id=l1.id andtimestamp<'2001-01-01' groupby id); There must be a better way to do this; any tips? Thanks, - Marc
В списке pgsql-sql по дате отправления: