SELECT B.RSV_USE_DT ,
USE_TM ,
CASE
WHEN USE_TM BETWEEN ASGN_FROM_TM AND ASGN_TO_TM
THEN 'X'
ELSE 'O'
END AS YN
FROM
(SELECT ASGN_DT,
RSV_USE_DT ,
TO_NUMBER(ASGN_FROM_TM) AS ASGN_FROM_TM ,
TO_NUMBER(ASGN_TO_TM) AS ASGN_TO_TM
FROM APLY_INFM
WHERE ACSS_FCIL_CD = '002'
AND RSV_USE_DT = '20130202'
AND ASGN_DT IS NOT NULL
) A,
(SELECT '20130202' AS RSV_USE_DT,
TM + LEVEL -1 AS USE_TM
FROM
(SELECT TO_NUMBER(USE_FROM_TM) AS TM
FROM INFM
WHERE USE_YN = 'Y'
AND ACSS_FCIL_CD = '002'
) CONNECT BY LEVEL - 1 <= 13
) B
WHERE B.RSV_USE_DT = A.RSV_USE_DT(+)
AND B.RSV_USE_DT = '20130202'
ORDER BY USE_TM
이렇게 하면 A의 레코드 갯수가 3개면
20130202 9 x
20130202 9 0
20130202 9 0
20130202 10 x
20130202 10 0
20130202 10 0
20130202 11 0
20130202 11 0
20130202 11 0
이런식으로 나옵니다.
저는
20130202 9 x
20130202 10 x
20130202 11 0
이렇게 나오게 하고 싶거든요.
잘 모르겠네요. 도와주세욤