[英]Hive create table error.
could you help me overcome the errors I get when I try to create the following table? 您能帮助我克服尝试创建下表时遇到的错误吗?
Thanks 谢谢
CREATE TABLE RANGE_FT (HOSP_VAR STRING, RANGE INT)
AS
SELECT 'EMR' ,MAX(emr_avg_score) - MIN(emr_avg_score) from JOIN9
UNION SELECT 'SCI' ,MAX(sci_avg_score) - MIN(sci_avg_score) from JOIN9
UNION SELECT 'ASTH' ,MAX(asth_avg_score) - MIN(asth_avg_score) from JOIN9
UNION SELECT 'HF' ,MAX(hf_avg_score) - MIN(hf_avg_score) from JOIN9
UNION SELECT 'SC' ,MAX(sc_avg_score) - MIN(sc_avg_score) from JOIN9
UNION SELECT 'PNEU' ,MAX(pneu_avg_score) - MIN(pneu_avg_score) from JOIN9
UNION SELECT 'PREV' ,MAX(prev_avg_score) - MIN(prev_avg_score) from JOIN9
UNION SELECT 'BC' ,MAX(BC_avg_score) - MIN(BC_avg_score) from JOIN9
UNION SELECT 'HEART' ,MAX(heart_avg_score) - MIN(heart_avg_score) from JOIN9
UNION SELECT 'PREG' ,MAX(preg_avg_score) - MIN(preg_avg_score) from JOIN9
;
line 7:6 missing ALL at 'SELECT'
第7:6行在“选择”中缺少所有内容
UNION
is not supported by your Hive version (and it is also not what you need here). 您的Hive版本不支持
UNION
(这里也不是您所需要的)。
Use UNION ALL
instead. 请改用
UNION ALL
。 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Union https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Union
UNION [ALL] requires identical schema from both sides. UNION [ALL]双方需要相同的架构。
In Hive, unlike other SQL dialects, not just the types should be similar but also the columns aliases. 在Hive中,与其他SQL方言不同,不仅类型应相似,而且列别名也应相似。 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Union
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Union
You cannot give a list of columns in your create statement. 您不能在create语句中提供列列表。
Add the relevant aliases to the SELECT clause. 将相关的别名添加到SELECT子句中。
This is a fixed version of your query 这是查询的固定版本
CREATE TABLE RANGE_FT
AS
SELECT 'EMR' as HOSP_VAR ,MAX (emr_avg_score) - MIN (emr_avg_score) as RANGE from JOIN9
UNION ALL SELECT 'SCI' as HOSP_VAR ,MAX (sci_avg_score) - MIN (sci_avg_score) as RANGE from JOIN9
UNION ALL SELECT 'ASTH' as HOSP_VAR ,MAX (asth_avg_score) - MIN (asth_avg_score) as RANGE from JOIN9
UNION ALL SELECT 'HF' as HOSP_VAR ,MAX (hf_avg_score) - MIN (hf_avg_score) as RANGE from JOIN9
UNION ALL SELECT 'SC' as HOSP_VAR ,MAX (sc_avg_score) - MIN (sc_avg_score) as RANGE from JOIN9
UNION ALL SELECT 'PNEU' as HOSP_VAR ,MAX (pneu_avg_score) - MIN (pneu_avg_score) as RANGE from JOIN9
UNION ALL SELECT 'PREV' as HOSP_VAR ,MAX (prev_avg_score) - MIN (prev_avg_score) as RANGE from JOIN9
UNION ALL SELECT 'BC' as HOSP_VAR ,MAX (BC_avg_score) - MIN (BC_avg_score) as RANGE from JOIN9
UNION ALL SELECT 'HEART' as HOSP_VAR ,MAX (heart_avg_score) - MIN (heart_avg_score) as RANGE from JOIN9
UNION ALL SELECT 'PREG' as HOSP_VAR ,MAX (preg_avg_score) - MIN (preg_avg_score) as RANGE from JOIN9
;
And here is an alternative solution with only a single SELECT 这是仅需一个SELECT的替代解决方案
create table RANGE_FT
as
select inline
(
array
(
struct ('EMR' ,MAX (emr_avg_score) - MIN (emr_avg_score) )
,struct ('SCI' ,MAX (sci_avg_score) - MIN (sci_avg_score) )
,struct ('ASTH' ,MAX (asth_avg_score) - MIN (asth_avg_score) )
,struct ('HF' ,MAX (hf_avg_score) - MIN (hf_avg_score) )
,struct ('SC' ,MAX (sc_avg_score) - MIN (sc_avg_score) )
,struct ('PNEU' ,MAX (pneu_avg_score) - MIN (pneu_avg_score) )
,struct ('PREV' ,MAX (prev_avg_score) - MIN (prev_avg_score) )
,struct ('BC' ,MAX (BC_avg_score) - MIN (BC_avg_score) )
,struct ('HEART' ,MAX (heart_avg_score) - MIN (heart_avg_score))
,struct ('PREG' ,MAX (preg_avg_score) - MIN (preg_avg_score) )
)
) as (HOSP_VAR,RANGE)
from JOIN9
;
This will work.As mentioned by Dudu you can not give column name while writing create with select. 这将起作用。正如Dudu所提到的,在编写带有select的create时不能提供列名。 You can use Union but performance wise UNION ALL is better.
您可以使用Union,但性能上最好选择UNION ALL。 Select based on your usecase
根据用例选择
CREATE TABLE RANGE_FT
AS
SELECT 'EMR' AS HOSP_VAR ,MAX(emr_avg_score) - MIN(emr_avg_score) AS `RANGE` from JOIN9
UNION SELECT 'SCI' AS HOSP_VAR ,MAX(sci_avg_score) - MIN(sci_avg_score) AS `RANGE` from JOIN9
UNION SELECT 'ASTH' AS HOSP_VAR ,MAX(asth_avg_score) - MIN(asth_avg_score) AS `RANGE` from JOIN9
UNION SELECT 'HF' AS HOSP_VAR ,MAX(hf_avg_score) - MIN(hf_avg_score) AS `RANGE` from JOIN9
UNION SELECT 'SC' AS HOSP_VAR ,MAX(sc_avg_score) - MIN(sc_avg_score) AS `RANGE` from JOIN9
UNION SELECT 'PNEU' AS HOSP_VAR ,MAX(pneu_avg_score) - MIN(pneu_avg_score) AS `RANGE` from JOIN9
UNION SELECT 'PREV' AS HOSP_VAR ,MAX(prev_avg_score) - MIN(prev_avg_score) AS `RANGE` from JOIN9
UNION SELECT 'BC' AS HOSP_VAR ,MAX(BC_avg_score) - MIN(BC_avg_score) AS `RANGE` from JOIN9
UNION SELECT 'HEART' AS HOSP_VAR ,MAX(heart_avg_score) - MIN(heart_avg_score) AS `RANGE` from JOIN9
UNION SELECT 'PREG' AS HOSP_VAR ,MAX(preg_avg_score) - MIN(preg_avg_score) AS `RANGE` from JOIN9
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.