Здравствуйте, Neco, Вы писали:
WITH t AS (
SELECT to_date('2014-11-01 21:26:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2014-11-01 22:20:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2014-11-02 04:30:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2014-11-02 06:15:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2014-11-02 07:42:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2014-12-01 20:30:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2014-12-01 22:20:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2014-12-02 04:25:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2014-12-02 06:15:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2014-12-02 07:40:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2015-01-01 21:24:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2015-01-01 21:31:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2015-01-01 22:20:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2015-01-02 04:30:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2015-01-02 06:15:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual UNION ALL
SELECT to_date('2015-01-02 07:43:00','yyyy-mm-dd hh24:mi:ss') oper_date FROM dual
)
SELECT oper_date,
first_value(oper_date) OVER(PARTITION BY grp ORDER BY oper_date) f_start,
first_value(oper_date) OVER(PARTITION BY grp ORDER BY oper_date DESC) f_finish
FROM (
SELECT oper_date, SUM(start_of_group) OVER(ORDER BY oper_date) grp
FROM (
SELECT oper_date,
CASE WHEN oper_date > nvl(lag(oper_date + 18/24) OVER(ORDER BY oper_date) , oper_date-1) THEN 1 ELSE 0 END start_of_group
FROM t
)
)