Здравствуйте, Darkman_VLT, Вы писали:
D_V>Имеется табличка
D_V>В итоге очень нужно получить это ввиде таблицы:
D_V>host_id created_on created_off
D_V>--example--
D_V>1 10:12 11:20
D_V>1 12:50 NULL
select t1.host_id, t1.created as created_on, min( t2.created ) as created_off
from t t1 left join t t2
on t2.host_id = t1.host_id
and t2.created > t1.created
where
t1.event_id = 1
and isnull( t2.event_id, 2 ) = 2
group by
t1.host_id, t1.created
D_V>P.S. SQL в реализации Postgres'a
Проверено на mssql. В Postgres должно быть также