테이블구조를 정확하게 몰라서
제가 임의로 구조를 정했습니다.
아래와 같이 테이블 구조를 가정해서 작성했는데
원하시는 바와 같으신지 확인하시기 바랍니다.
좋은 하루 되세요.
/*
column a : 사원번호
column b : 금액
column c : 월
column d : 지급코드
- 1 : 월급
- 2 : 상여금
- 3 : 특별상여금
다고 가정하면
*/
select a.a
,sum(case when a.c=1 and a.d=1 then a.b end) 1m
,sum(case when a.c=2 and a.d=1 then a.b end) 2m
,sum(case when a.c=3 and a.d=1 then a.b end) 3m
,sum(case when a.c=4 and a.d=1 then a.b end) 4m
,sum(case when a.c=5 and a.d=1 then a.b end) 5m
,sum(case when a.c=6 and a.d=1 then a.b end) 6m
,sum(case when a.c=7 and a.d=1 then a.b end) 7m
,sum(case when a.c=8 and a.d=1 then a.b end) 8m
/* 9월~12월 생략 */
,sum(case when a.d=2 then a.b end) bonus
,sum(case when a.d=3 then a.b end) special_bonus
from (
select '11111' a, 100 b, 1 c, 1 d from dual union all
select '11112', 100, 1, 1 from dual union all
select '11113', 100, 1, 1 from dual union all
select '11111', 100, 2, 1 from dual union all
select '11112', 100, 2, 1 from dual union all
select '11113', 100, 2, 1 from dual union all
select '11111', 100, 3, 1 from dual union all
select '11112', 100, 3, 1 from dual union all
select '11113', 100, 3, 1 from dual union all
select '11111', 100, 4, 1 from dual union all
select '11112', 100, 4, 1 from dual union all
select '11113', 100, 4, 1 from dual union all
select '11111', 100, 5, 1 from dual union all
select '11112', 100, 5, 1 from dual union all
select '11113', 100, 5, 1 from dual union all
select '11111', 100, 6, 1 from dual union all
select '11112', 100, 6, 1 from dual union all
select '11113', 100, 6, 1 from dual union all
select '11111', 100, 7, 1 from dual union all
select '11112', 100, 7, 1 from dual union all
select '11113', 100, 7, 1 from dual union all
select '11111', 100, 8, 1 from dual union all
select '11112', 100, 8, 1 from dual union all
select '11113', 100, 8, 1 from dual union all
select '11111', 100, 2, 2 from dual union all
select '11112', 100, 2, 2 from dual union all
select '11113', 100, 2, 2 from dual union all
select '11111', 100, 7, 2 from dual union all
select '11112', 100, 7, 2 from dual union all
select '11113', 100, 7, 2 from dual union all
select '11111', 100, 3, 3 from dual union all
select '11112', 100, 3, 3 from dual union all
select '11113', 100, 3, 3 from dual union all
select '11111', 100, 8, 3 from dual union all
select '11112', 100, 8, 3 from dual union all
select '11113', 100, 8, 3 from dual
) a
group by a.a