简体   繁体   English

HIVE从子查询创建表

[英]HIVE Create Table from SubQuery

this is my code: 这是我的代码:

create table sw_tmp6_gar_crm as
SELECT * FROM(
  select as_fid_x_gara.dat_fine_perio        as dat_fine_perio,
         as_fid_x_gara.cod_soc               as cod_soc, 
         as_fid_x_gara.cod_kto_gar           as cod_kto_gar, 
         as_fid_x_gara.cod_fido              as cod_fido,
         fid.dat_delib             as dat_delib, 
         fid.dat_scad              as dat_scad  

  from   it_soc_x_fv,
         as_fid_x_gara   ,
         rt_fidi         
  where  it_soc_x_fv.flg_tp_soc     in ('C','N')
    and  as_fid_x_gara.dat_fine_perio   = 2008-03-06
    and  as_fid_x_gara.cod_soc          = it_soc_x_fv.cod_soc
    and  rt_fidi.dat_fine_perio   = as_fid_x_gara.dat_fine_perio
    and  rt_fidi.cod_soc          = as_fid_x_gara.cod_soc       
    and  rt_fidi.cod_fido_tecnico = as_fid_x_gara.cod_fido 
     )         
;

I receive the following error: 我收到以下错误:

error while compiling statement: failed: parseexception line 10:9 cannot recognize input near 'it_soc_x_fv' ',' 'as_fid_x_gara' in from source 编译语句时出错:失败:parseexception第10:9行无法识别源中“ it_soc_x_fv”,“ as_fid_x_gara”附近的输入

Can you help me in that? 你能帮我吗?

You need to give an alias name for the sub-query. 您需要为子查询提供alias The below one should work. 下面的一个应该工作。

create table sw_tmp6_gar_crm as
SELECT * FROM(
  select as_fid_x_gara.dat_fine_perio        as dat_fine_perio,
         as_fid_x_gara.cod_soc               as cod_soc, 
         as_fid_x_gara.cod_kto_gar           as cod_kto_gar, 
         as_fid_x_gara.cod_fido              as cod_fido,
         fid.dat_delib             as dat_delib, 
         fid.dat_scad              as dat_scad  

  from   it_soc_x_fv,
         as_fid_x_gara   ,
         rt_fidi         
  where  it_soc_x_fv.flg_tp_soc     in ('C','N')
    and  as_fid_x_gara.dat_fine_perio   = 2008-03-06
    and  as_fid_x_gara.cod_soc          = it_soc_x_fv.cod_soc
    and  rt_fidi.dat_fine_perio   = as_fid_x_gara.dat_fine_perio
    and  rt_fidi.cod_soc          = as_fid_x_gara.cod_soc       
    and  rt_fidi.cod_fido_tecnico = as_fid_x_gara.cod_fido 
     ) tmp         
;

But as mentioned in the comments, you don't need a sub-query. 但是正如评论中提到的那样,您不需要子查询。

You haven't aliased the tables correctly. 您没有正确别名表。 In your from statement you haven't mentioned any aliases for tables and in your select columns you are saying fid.dat_delib, fid.dat_scad. 在您的from语句中,您没有提到表的别名,在您选择的列中,您说的是fid.dat_delib,fid.dat_scad。

But there is no fid table or alias in your query. 但是查询中没有fid表或别名。

As mentioned earlier, there is no need of sub query, you can directly write a query with out sub query. 如前所述,不需要子查询,您可以直接编写查询而无需子查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM