Answer the question
In order to leave comments, you need to log in
How can I find out the time during which a parameter had a certain value from the event log?
There is an event log table for trigger metric changes (on/off) with the following structure:
Table `log`:
+-------------+----------+--------------------------+
| metric_type | int | Тип метрики |
+-------------+----------+--------------------------+
| date_change | datetime | Дата изменения состояния |
+-------------+----------+--------------------------+
| state | tinyint | Состояние (вкл./выкл.) |
+-------------+----------+--------------------------+
+-------------+---------------------+-------+
| metric_type | date_change | state |
+-------------+---------------------+-------+
| 1 | 2017-04-20 10:00:00 | 0 |
+-------------+---------------------+-------+
| 1 | 2017-04-27 22:00:00 | 1 |
+-------------+---------------------+-------+
| 1 | 2017-06-02 10:00:00 | 0 |
+-------------+---------------------+-------+
Answer the question
In order to leave comments, you need to log in
You need to join this table to itself, but with a shift of one line. Here is a clumsy but working solution in ORACLE:
select t1.metric_type, t1.state, (t2.date_change - t1.date_change) as diff
from
(
select rownum as n, metric_type, state, date_change
from
(
select *
from someTable
order by metric_type, date_change
)) t1
left join (select rownum as n, metric_type, state, date_change
from
(
select *
from someTable
order by metric_type, date_change
)) t2 on (t1.n = t2.n+1 and t1.metric_type = t2.metric_type)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question