图a
图b
//创建学生信息表
create table ods_zq_hzllzh_ddl
(id int,name string,Chinese double,English double,Math double);//
//插入学生信息
INSERT INTO ods_zq_hzllzh_ddl VALUES
(1,'Linda',90,91,92);
//检查是否插入成功
SELECT * FROM ods_zq_hzllzh_ddl;
//创建字段表,第一个字段为‘name’
create table ods_zq_hzllzhTest_ddl
(id int,field_name_list string);
//插入字段
INSERT INTO ods_zq_hzllzhTest_ddl VALUES
(1,'Chinese'),
(2,'English'),
(3,'Math');
//检查是否插入成功
SELECT * FROM ods_zq_hzllzhTest_ddl;
select id,
(concat_ws(',',cast(Chinese AS STRING ),cast(English AS STRING ),cast(Math AS STRING ) ))
AS Linda_1
from ods_zq_hzllzh_ddl;t1
第一步:先将t2功能写好
SELECT Linda_2,rank() over(ORDER BY Linda_2 ) AS id
FROM t1
LATERAL VIEW explode(split(t1.Linda_1,',') ) test AS Linda_2;t2
第二步:再将t1代入,下同(注意,代入时不要带分号)
SELECT Linda_2,rank() over(ORDER BY Linda_2 ) AS id
FROM (select id,(concat_ws(',',cast(Chinese AS STRING ),cast(English AS STRING ),cast(Math AS STRING ) ))AS Linda_1
from ods_zq_hzllzh_ddl)t1
LATERAL VIEW explode(split(t1.Linda_1,',') ) test AS Linda_2;t2
第一步:先将t3功能写好
SELECT t2.id,field_name_list AS `name`,Linda_2 AS `Linda`
FROM t2,ods_zq_hzllzhTest_ddl tt
WHERE t2.id=tt.id;
第二步:再将t2代入(注意,代入时不要带分号)
SELECT t2.id,field_name_list AS `name`,Linda_2 AS `Linda`
FROM (SELECT Linda_2,rank() over(ORDER BY Linda_2 ) AS id
FROM (select id,(concat_ws(',',cast(Chinese AS STRING ),cast(English AS STRING ),cast(Math AS STRING ) ))AS Linda_1
from ods_zq_hzllzh_ddl)t1
LATERAL VIEW explode(split(t1.Linda_1,',') ) test AS Linda_2)t2,ods_zq_hzllzhTest_ddl tt
WHERE t2.id=tt.id;t3
在此非常感谢三位老师的指导OVO