Запрос можно покороче:
select
t1.epoch,
t1.value,
t1.message,
(select `value` from data where epoch < t1.epoch and message = "isig_level" ORDER BY epoch DESC LIMIT 1) prev_value,
(select `value` from data where epoch > t1.epoch and message = "isig_level" ORDER BY epoch LIMIT 1) next_value
from data t1
where t1.value = 0 and t1.message = "isig_level"
and prev_value <> 0 and next_value <> 0
order by t1.epoch
@vvzvlad
Что не так с этим запросом:
select
t2.epoch,
t2.`key`,
t2.`value`
from
(
select
t1.`value`,
t1.`key`,
t1.epoch,
t1.message,
(select `value` from data where epoch < t1.epoch and message = "isig_level" ORDER BY epoch DESC LIMIT 1) prev_value,
(select `value` from data where epoch > t1.epoch and message = "isig_level" ORDER BY epoch LIMIT 1) next_value
from data t1
where t1.value = 0 and t1.message = "isig_level"
order by t1.epoch
) t2
where t2.prev_value = 0 and t2.next_value = 0
Проверь
print message.from_user.id
подставь в запрос и выполни в БД.