세로 데이터를 가로로 조회하기
/******************************************************
* 원래 데이터
*******************************************************/
select
gi_num, m_id,
row_number() over(
partition by gi_num
order by gi_num, m_id
) rn
from user_group
where 1 = 1
GI_NUM M_ID RN
----------- -------------------- ----------
2 jhee 1
25 cbcsky 1
25 jh22 2
25 jhee 3
26 cbcsky 1
5 rows selected
/******************************************************
* 변환된 데이터
*******************************************************/
select
gi_num
, (max (decode (rn, 1, m_id))) id1
, (max (decode (rn, 2, m_id))) id2
, (max (decode (rn, 3, m_id))) id3
, (max (decode (rn, 4, m_id))) id4
, (max (decode (rn, 5, m_id))) id5
from (
select
gi_num, m_id,
row_number() over(
partition by gi_num
order by gi_num, m_id
) rn
from user_group
) group by gi_num
GI_NUM ID1 ID2 ID3 ID4
----------- -------------------- -------------------- -------------------- -----
2 jhee
25 cbcsky jh22 jhee
26 cbcsky
3 rows selected