sql operation with respect to the key-value data rows into columns

insert into table ${db_name}.uv_month_20190529 
select 
k_v['${date}'] as date_id,
k_v['0'] as  0h,
k_v['1'] as  1h ,
k_v['2'] as 2h,
k_v['3'] as 3h,
k_v['4'] as 4h,
k_v['5'] as 5h,
k_v['6'] as 6h,
k_v['7'] as 7h,
k_v['8'] as 8h,
k_v['9'] as 9h,
k_v['10'] as 10h,
k_v['11'] as 11h,
k_v['12'] as 12h,
k_v['13'] as13h, 
k_v [ ' 14 ' ] as 14h, 
k_v [ ' 15 ' ] as 15h, 
k_v [ ' 16 ' ] as 16h, 
k_v [ ' 17 ' ] as 17h, 
k_v [ ' 18 ' ] as 18h, 
k_v [ ' 19 ' ] as 19h, 
k_v [ ' 20 ' ] as 20h, 
k_v [ ' 21 ' ] as 21h,
Kv [ ' 22 is ' ] AS 22h, 
Kv [ ' 23 is ' ] AS 23 h
 from (
 SELECT str_to_map (CONCAT_WS ( ' , ' , collect_list (the concat (hour, ' : ' , UV)))) Kv 
 from $ {db_temp}. _ $ {DATE} tmp_ol_xianxia_store_table1 
) T; 

this sql is figured out for each hour uv transpose operation, the final result obtained.

 

Guess you like

Origin www.cnblogs.com/gxgd/p/11038496.html