■ Pivot - 행을 열로 변환
# Sample Query - 복사, 붙여 넣기로 테스트
select ymd, nvl(총무과, 0) as 총무과, nvl(인사과, 0) as 인사과, nvl(전산실, 0) as 전산실
from (select a.ymd, a.dept, count(1) as cnt
from (select '20230901' as ymd, '총무과' as dept from dual
union all
select '20230901' as ymd, '인사과' as dept from dual
union all
select '20230902' as ymd, '전산실' as dept from dual
union all
select '20230902' as ymd, '총무과' as dept from dual
union all
select '20230903' as ymd, '인사과' as dept from dual) a
group by a.ymd, a.dept) a
pivot (sum(cnt) for dept in ('총무과' as 총무과, '인사과' as 인사과, '전산실' as 전산실))
order by ymd
■ UnPivot
# Sample Query - 복사, 붙여 넣기로 테스트
select *
from (select 11 as apple, 2 as lemon, 17 as grape from dual
union all
select 5 as apple, 7 as lemon, 12 as grape from dual
union all
select 8 as apple, 6 as lemon, 7 as grape from dual
union all
select 9 as apple, 2 as lemon, 9 as grape from dual
union all
select 3 as apple, 1 as lemon, 1 as grape from dual)
unpivot (count for fruit in (apple, lemon, grape))
order by fruit
'Database > Oracle' 카테고리의 다른 글
ORA-24324, ORA-01041 서비스 처리 초기화, 내부오류. hostdef (0) | 2024.01.15 |
---|---|
ORA-12514 리스너에 등록되지 않았습니다.(해결) (0) | 2024.01.14 |
Oracle Bigfile, Smallfile 차이 (0) | 2023.08.09 |
오라클 SID vs ServiceName, SID 여러 개 구성하는 이유 (0) | 2023.07.22 |
INS-35075 오류 - 오라클 완전 삭제 방법과 완전 삭제가 어려운 이유 (0) | 2023.07.20 |