Greetings!
I currently have a script with pivot function in it. Attached you will find a JPEG file of my script (for ease of reading) and two files that shows current result of the script and desired result.
My script groups result based on nationalities (UAE & Non-UAE). I would like to further group it by gender. The 'Desired.JPEG' shows how I would like to display my result. Will I be able to further pivot my result to break down the nationality group by gender? Below you will find my script.
Script
.............................................................................................................................................................................................................................................................................................
select *
from
(
select Ou.SGBSTDN_PIDM PIDM, decode(substr(Ou.SGBSTDN_CAMP_CODE,3,1),'M','M','W','W') Gender, STVCOLL_DESC College,
STVMAJR_DESC Major,
case
when STVNATN_NATION = 'United Arab Emirates' then 'UAE'
else 'Non_UAE'
end as UAE_Non_UAE
from SPRIDEN, SGBSTDN Ou, STVCOLL, STVMAJR, GOBINTL, STVNATN
where SPRIDEN_PIDM = Ou.SGBSTDN_PIDM
and SPRIDEN_CHANGE_IND is null
and Ou.SGBSTDN_STST_CODE in ('AS','AW','CW','DA','DW','OW','PA','RA','SP','WN','XP','XT')
and Ou.SGBSTDN_TERM_CODE_EFF = ( select max(Inn.SGBSTDN_TERM_CODE_EFF)
from SGBSTDN Inn
where Inn.SGBSTDN_PIDM = Ou.SGBSTDN_PIDM
and Inn.SGBSTDN_TERM_CODE_EFF <= '201610'
)
and (Ou.SGBSTDN_COLL_CODE_1 = '05' or Ou.SGBSTDN_MAJR_CODE_1 in ('H094', 'NURS', 'NURB'))
and Ou.SGBSTDN_COLL_CODE_1 = STVCOLL_CODE
and Ou.SGBSTDN_MAJR_CODE_1 = STVMAJR_CODE
and Ou.SGBSTDN_PIDM = GOBINTL_PIDM(+)
and GOBINTL_NATN_CODE_LEGAL = STVNATN_CODE(+)
)
pivot
(
count (PIDM)--, count (Gender) as MW
for UAE_Non_UAE in ('UAE' as UAE, 'Non_UAE' as Non_UAE)
)
order by College, Major
;
.............................................................................................................................................................................................................................................................................................
Result
.............................................................................................................................................................................................................................................................................................
GENDER | COLLEGE | MAJOR | UAE | NON_UAE |
M | Health Sciences | Clinical Nutrition & Dietetics | 0 | 2 |
W | Health Sciences | Clinical Nutrition & Dietetics | 22 | 209 |
M | Health Sciences | Environmental Health | 2 | 12 |
W | Health Sciences | Environmental Health | 24 | 23 |
M | Health Sciences | Health Services Administration | 1 | 5 |
W | Health Sciences | Health Services Administration | 6 | 45 |
M | Health Sciences | Medical Diagnostic Imag - Bdg | 0 | 6 |
W | Health Sciences | Medical Diagnostic Imag - Bdg | 0 | 3 |
.............................................................................................................................................................................................................................................................................................
Desired
.............................................................................................................................................................................................................................................................................................
UAE | Non_UAE | ||||
COLLEGE | MAJOR | M | W | M | W |
Health Sciences | Clinical Nutrition & Dietetics | 0 | 22 | 2 | 209 |
Health Sciences | Environmental Health | 2 | 24 | 12 | 23 |
Health Sciences | Health Services Administration | 1 | 6 | 5 | 45 |
Health Sciences | Medical Diagnostic Imag - Bdg | 0 | 0 | 6 | 3 |
.............................................................................................................................................................................................................................................................................................