Сдвигайте строки к столбцам, используя динамический запрос
Я реализовал следующий запрос для поворота col_nm от строки к столбцу:
select grp_id,orig_businesseffectivedate,
max(case when col_nm= 'bus_seg_cd' then col_val end) as bus_seg_cd,
max(case when col_nm= 'dft_insur_cd' then col_val end) as dft_insur_cd,
max(case when col_nm= 'drc_indrct_ind' then col_val end) as drc_indrct_ind,
max(case when col_nm= 'ifrs9_stream' then col_val end) as ifrs9_stream,
max(case when col_nm= 'stff_loan_cd' then col_val end) as stff_loan_cd,
max(case when col_nm= 'loan_prps_cd' then col_val end) as loan_prps_cd,
max(case when col_nm= 'org_bu' then col_val end) as org_bu,
max(case when col_nm= 'prime_ind' then col_val end) as prime_ind,
max(case when col_nm= 'rcrr_prd_cd' then col_val end) as rcrr_prd_cd,
max(case when col_nm= 'scrty_ind' then col_val end) as scrty_ind,
max(case when col_nm= 'stff_loan_cd' then col_val end) as stff_loan_cd
from crz_shrd.cpp_rcrr_prd_mappng_grp_dtl
group by grp_id,orig_businesseffectivedate
и следующий вывод является правильным: результат запроса
Интересно, если col_nm получит новое значение, есть ли способ обработать его динамически или сделать поворот универсальным?