SELECT TASK_ID
FROM (SELECT TASK_ID, PRE_TASK_ID
FROM (SELECT T.*,
ROW_NUMBER() OVER(PARTITION BY T.TASK_ID ORDER BY T.target_level) R_ID
FROM (select V.*, r.target_id, C.target_level
from v_pipe_task v,
PIPE_TASK_TARGET r,
PIPE_TARGET_CONFIG c
where v.TASK_ID = r.task_ID
AND R.TARGET_ID = C.TARGET_ID) T) A
WHERE A.R_ID = 1
AND status = 1
AND run_status = 1
AND next_time < sysdate
order by next_time, TARGET_LEVEL) TASK_TABLE
WHERE PRE_TASK_ID NOT IN
(SELECT TASK_ID
FROM (SELECT T.*,
ROW_NUMBER() OVER(PARTITION BY T.TASK_ID ORDER BY T.target_level) R_ID
FROM (select V.*, r.target_id, C.target_level
from v_pipe_task v,
PIPE_TASK_TARGET r,
PIPE_TARGET_CONFIG c
where v.TASK_ID = r.task_ID
AND R.TARGET_ID = C.TARGET_ID) T) A
WHERE A.R_ID = 1
AND status = 1
AND run_status = 1
AND next_time < sysdate)
FROM (SELECT TASK_ID, PRE_TASK_ID
FROM (SELECT T.*,
ROW_NUMBER() OVER(PARTITION BY T.TASK_ID ORDER BY T.target_level) R_ID
FROM (select V.*, r.target_id, C.target_level
from v_pipe_task v,
PIPE_TASK_TARGET r,
PIPE_TARGET_CONFIG c
where v.TASK_ID = r.task_ID
AND R.TARGET_ID = C.TARGET_ID) T) A
WHERE A.R_ID = 1
AND status = 1
AND run_status = 1
AND next_time < sysdate
order by next_time, TARGET_LEVEL) TASK_TABLE
WHERE PRE_TASK_ID NOT IN
(SELECT TASK_ID
FROM (SELECT T.*,
ROW_NUMBER() OVER(PARTITION BY T.TASK_ID ORDER BY T.target_level) R_ID
FROM (select V.*, r.target_id, C.target_level
from v_pipe_task v,
PIPE_TASK_TARGET r,
PIPE_TARGET_CONFIG c
where v.TASK_ID = r.task_ID
AND R.TARGET_ID = C.TARGET_ID) T) A
WHERE A.R_ID = 1
AND status = 1
AND run_status = 1
AND next_time < sysdate)