-- 그냥 FULL OUTER JOIN WITH T1 (ID , USER_NO , DT , BEGIN , END , TYPE , DETAIL , ISUUE ) AS ( SELECT '6' , '3' , '2013-05-21' , '09:00:00' , '16:00:00' ,'1','trac 설정 및 소스 바인딩' ,'' FROM DUAL UNION ALL SELECT '8' , '3' , '2013-05-21' , '16:00:00' , '17:00:00' ,'4','개발장비 이동 및 네트워크 구성' ,'' FROM DUAL UNION ALL SELECT '10', '3' , '2013-05-21' , '17:00:00' , '22:00:00' ,'5','샘플 프로젝트 개선 (미완료)' , null FROM DUAL ),T2 (ID , USER_NO , DT , DETAIL ) AS( SELECT '4' , '3' , '2013-05-21' , '샘플 프로젝트 개선' FROM DUAL UNION ALL SELECT '6' , '3' , '2013-05-21' , '교육자료 제작' FROM DUAL ) SELECT * FROM (SELECT rownum num , T1.* FROM T1 ) T1 FULL OUTER JOIN (SELECT rownum num , T2.* FROM T2 ) T2 ON T1.num = T2.num
SELECT user_no, date, rn , MIN(id1 ) id1 , MIN(user_no1) user_no1 , MIN(date1 ) date1 , MIN(id2 ) id2 , MIN(user_no2) user_no2 , MIN(date2 ) date2 FROM ( SELECT @rn := CASE WHEN @dt = date THEN @rn + 1 ELSE 1 END rn , @dt := date , user_no , date , id id1 , user_no user_no1 , date date1 , NULL id2 , NULL user_no2 , NULL date2 FROM (SELECT 6 id, 3 user_no, '2013.05.21' date UNION ALL SELECT 8, 3, '2013.05.21' UNION ALL SELECT 10, 3, '2013.05.21' UNION ALL SELECT 11, 3, '2013.05.22' UNION ALL SELECT 12, 3, '2013.05.22' ORDER BY user_no, date, id ) t1 , (SELECT @rn := 0 , @dt := '' ) r UNION ALL SELECT @rn := CASE WHEN @dt = date THEN @rn + 1 ELSE 1 END rn , @dt := date , user_no , date , NULL id1 , NULL user_no1 , NULL date1 , id id2 , user_no user_no2 , date date2 FROM (SELECT 4 id, 3 user_no, '2013.05.21' date UNION ALL SELECT 6, 3, '2013.05.21' UNION ALL SELECT 7, 3, '2013.05.22' UNION ALL SELECT 8, 3, '2013.05.22' UNION ALL SELECT 9, 3, '2013.05.22' ORDER BY user_no, date, id ) t2 , (SELECT @rn := 0 , @dt := '' ) r ) x GROUP BY user_no, date, rn ORDER BY user_no, date, rn ;