[SQL1] SELECT B.MENU_ID , B.MENU_NM , A.ATRT_ID_GROUP FROM COT_ATRT_GROUP_MPNG A , COT_AO_INFO B WHERE A.MENU_SEQ = B.MENU_SEQ ORDER BY B.MENU_ID, B.MENU_NM
[SQL1 결과]
MENU_ID | MENU_NM | ATRT_ID_GROUP |
AMBlbd | AM게시판 | AM100 |
AMBlbd | AM게시판 | AM200 |
AMBlbd | AM게시판 | AM300 |
AMBlbd | AM게시판 | AM400 |
AMBlbd | AM게시판 | SUPER |
ActvMtlBasi | 리쿠르팅자료 | TM100 |
ActvMtlBasi | 리쿠르팅자료 | TM200 |
ActvMtlBasi | 리쿠르팅자료 | TM300 |
ActvMtlBasi | 리쿠르팅자료 | SUPER |
ActvMtlBasi | 리쿠르팅자료 | HEAD |
CantItro | 후보자도입 | FC100 |
CantItro | 후보자도입 | FC200 |
CantItro | 후보자도입 | SUPER |
CantItro | 후보자도입 | HEAD |
.
.
.
조회하면 이렇게 결과가 나옵니다
두 테이블에 공통된 컬럼은 MENU_SEQ, MENU_ID 입니다
이거를 조회해서 원하는 결과 모양은
MENU_ID | MENU_NM | ATRT_ID_GROUP |
AMBlbd | AM게시판 | AM100 |
AM200 | ||
AM300 | ||
AM400 | ||
SUPER | ||
ActvMtlBasi | 리쿠르팅자료 | TM100 |
TM200 | ||
TM300 | ||
SUPER | ||
HEAD | ||
CantItro | 후보자도입 | FC100 |
FC200 | ||
SUPER | ||
HEAD |
이렇게 조회 결과가 나옫도록 하고 싶은데.. 쿼리를 어떻게 짜야 가능한지 감이 안오네요ㅠㅠ
사용하는 DB는 오라클입니다
WITH cot_atrt_group_mpng AS ( SELECT 1 menu_seq, 'AM100' atrt_id_group FROM dual UNION ALL SELECT 1, 'AM200' FROM dual UNION ALL SELECT 1, 'AM300' FROM dual UNION ALL SELECT 1, 'AM400' FROM dual UNION ALL SELECT 1, 'SUPER' FROM dual UNION ALL SELECT 2, 'TM100' FROM dual UNION ALL SELECT 2, 'TM200' FROM dual UNION ALL SELECT 2, 'TM300' FROM dual UNION ALL SELECT 2, 'SUPER' FROM dual UNION ALL SELECT 2, 'HEAD' FROM dual UNION ALL SELECT 3, 'FC100' FROM dual UNION ALL SELECT 3, 'FC200' FROM dual UNION ALL SELECT 3, 'SUPER' FROM dual UNION ALL SELECT 3, 'HEAD' FROM dual ) , cot_ao_info AS ( SELECT 1 menu_seq, 'AMBlbd' menu_id, 'AM게시판' menu_nm FROM dual UNION ALL SELECT 2, 'ActvMtlBasi', '리쿠르팅자료' FROM dual UNION ALL SELECT 3, 'CantItro' , '후보자도입' FROM dual ) SELECT DECODE(rn, 1, menu_id) menu_id , DECODE(rn, 1, menu_nm) menu_nm , atrt_id_group FROM (SELECT b.menu_id , b.menu_nm , a.atrt_id_group , ROW_NUMBER() OVER(PARTITION BY b.menu_id ORDER BY a.atrt_id_group) rn FROM cot_atrt_group_mpng a , cot_ao_info b WHERE a.menu_seq = b.menu_seq ) ;