안녕하세요
작업자 편의사항 인데요
생각보다 많이 힘드네요
작업자들이 시간(초)단위로 작업한 파일이 있습니다
근데 작업을 완료 하지 않았을경우나 부득이 하게 종료했을경우 정전이 되었을경우나 등등
선택한 시간기준으로 맨앞의 값과 맨끝의 값을 가져오고 싶습니다.
최초의 값과 끝의 값을 가져오고 목록을 로드한 다음 끝의 값의 기준으로
작업을 연결 시키고 싶습니다.
데이타는 초단위 기준의 0~2초기준으로 연결 되어 있습니다.
자정을 넘는경우도 있어서 이게 문제네요
0~2초 기준에 부합되지 않을경우는 다른 그룹 데이터 입니다.
해당 그룹 이후의 최초값도 가져와서 충돌을 방지하고 싶습니다. 없으면 null 입니다.
데이타는 다음과 같습니다.
WITH T AS (
SELECT TO_DATE ( START_DATE , 'YYYY-MM-DD HH24:MI:SS') START_DATE , TO_DATE ( END_DATE , 'YYYY-MM-DD HH24:MI:SS') END_DATE FROM (
Select '2016-01-27 04:55:35' , '2016-01-27 04:56:00' from dual UNION ALL
Select '2016-01-27 04:56:00' , '2016-01-27 05:00:37' from dual UNION ALL
Select '2016-01-27 05:00:37' , '2016-01-27 05:00:44' from dual UNION ALL
Select '2016-01-27 05:00:44' , '2016-01-27 05:07:54' from dual UNION ALL
Select '2016-01-27 05:07:54' , '2016-01-27 05:08:01' from dual UNION ALL
Select '2016-01-27 05:08:01' , '2016-01-27 05:08:10' from dual UNION ALL
Select '2016-01-27 05:08:11' , '2016-01-27 05:13:44' from dual UNION ALL
Select '2016-01-27 05:13:44' , '2016-01-27 05:13:59' from dual UNION ALL
Select '2016-01-27 05:13:59' , '2016-01-27 05:55:11' from dual UNION ALL
Select '2016-01-27 05:55:11' , '2016-01-27 05:55:23' from dual UNION ALL
Select '2016-01-27 05:55:23' , '2016-01-27 05:55:33' from dual UNION ALL
Select '2016-01-27 05:55:33' , '2016-01-27 06:00:12' from dual UNION ALL
Select '2016-01-27 06:00:12' , '2016-01-27 06:00:37' from dual UNION ALL
------------------------------------------------------------------------------------------------------
Select '2016-01-27 06:20:36' , '2016-01-27 06:20:45' from dual UNION ALL
Select '2016-01-27 06:20:45' , '2016-01-27 06:22:38' from dual UNION ALL
Select '2016-01-27 06:22:38' , '2016-01-27 06:22:59' from dual UNION ALL
Select '2016-01-27 06:22:59' , '2016-01-27 06:23:45' from dual UNION ALL
Select '2016-01-27 06:23:45' , '2016-01-27 06:24:15' from dual UNION ALL
Select '2016-01-27 06:24:15' , '2016-01-27 06:24:46' from dual UNION ALL
Select '2016-01-27 06:24:46' , '2016-01-27 07:43:05' from dual UNION ALL
Select '2016-01-27 07:43:05' , '2016-01-27 07:45:21' from dual UNION ALL
Select '2016-01-27 07:45:21' , '2016-01-27 07:46:10' from dual UNION ALL
Select '2016-01-27 07:46:10' , '2016-01-27 07:46:20' from dual UNION ALL
Select '2016-01-27 07:46:20' , '2016-01-27 07:47:41' from dual UNION ALL
Select '2016-01-27 07:47:41' , '2016-01-27 07:49:31' from dual UNION ALL
Select '2016-01-27 07:49:31' , '2016-01-27 07:49:51' from dual UNION ALL
Select '2016-01-27 07:49:51' , '2016-01-27 07:50:37' from dual UNION ALL
Select '2016-01-27 07:50:37' , '2016-01-27 08:24:47' from dual UNION ALL
Select '2016-01-27 08:24:47' , '2016-01-27 08:25:49' from dual UNION ALL
------------------------------------------------------------------------------------------------------
Select '2016-01-27 09:26:55' , '2016-01-27 09:30:21' from dual UNION ALL
Select '2016-01-27 09:30:21' , '2016-01-27 09:30:27' from dual UNION ALL
Select '2016-01-27 09:30:27' , '2016-01-27 09:30:44' from dual UNION ALL
Select '2016-01-27 09:30:44' , '2016-01-27 09:42:23' from dual UNION ALL
Select '2016-01-27 09:42:23' , '2016-01-27 09:42:30' from dual UNION ALL
Select '2016-01-27 09:42:30' , '2016-01-27 09:42:40' from dual UNION ALL
Select '2016-01-27 09:42:40' , '2016-01-27 09:43:30' from dual UNION ALL
Select '2016-01-27 09:43:30' , '2016-01-27 09:43:50' from dual UNION ALL
Select '2016-01-27 09:43:50' , '2016-01-27 09:44:06' from dual
)
)
SELECT * FROM T
2016-01-27 06:24:00 기준이라면
최초작업일자는 2016-01-27 06:20:36 이며
최종 작업일자는 2016-01-27 08:25:49
제한선은 2016-01-27 09:26:55 입니다.
감사합니다.
|