Re: how to remove a for-loop from programming language and put it into the query?
| От | Pedro Zorzenon Neto |
|---|---|
| Тема | Re: how to remove a for-loop from programming language and put it into the query? |
| Дата | |
| Msg-id | 4C31F9B3.8050607@mandic.com.br обсуждение исходный текст |
| Ответ на | Re: how to remove a for-loop from programming language and put it into the query? (Thom Brown <thombrown@gmail.com>) |
| Ответы |
Re: how to remove a for-loop from programming language and
put it into the query?
|
| Список | pgsql-general |
> I'm probably misunderstanding the problem, but can't you just do:
>
> SELECT
> diag_value
> FROM
> diagnose_logs
> WHERE
> ts <= '2009-12-25 23:59:59'
> AND
> hardware_id BETWEEN 1 AND 500
> ORDER BY
> ts DESC
> LIMIT 1
Hi Thom,
Yes, I think you misunderstood.
An example of a table:
hardware_id | ts | diag_value
1 | 2009-12-25 14:00:00 | 43.5 (*)
1 | 2009-12-26 15:00:00 | 43.6
1 | 2009-12-24 13:00:00 | 43.7
2 | 2009-12-24 15:00:00 | 43.8 (*)
2 | 2009-12-24 14:00:00 | 43.9
2 | 2009-12-24 14:16:00 | 43.9
2 | 2009-12-27 14:00:00 | 44.0
I need to get the "most recent" value before "2009-12-25 23:59:59" from
every hardware_id.
For hardware_id=1, the value would be:
1 | 2009-12-25 14:00:00 | 43.5
for hardware_id=2, the value would be:
2 | 2009-12-24 15:00:00 | 43.8
I need a query that will return me those lines marked with (*) :-) is
this possible?
Thanks!
В списке pgsql-general по дате отправления: