使用Hive查询将行旋转到列

时间:2018-08-08 21:26:22

标签: sql hadoop hive hiveql hive-query

我实现了以下查询以将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

,以下是看起来正确的输出: result of the query

我想知道col_nm是否获得新值,是否有办法动态处理它或使透视成为通用?

0 个答案:

没有答案