HIVE从SubQuery创建表

时间:2014-08-07 18:24:33

标签: sql hadoop hive

这是我的代码:

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 
     )         
;

我收到以下错误:

  编译语句时出现

错误:失败:parseexception第10行:9   无法识别'it_soc_x_fv''附近的输入,''as_fid_x_gara'来自   源

你可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

您需要为子查询指定一个alias名称。下面的一个应该可以工作。

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         
;

但正如评论中所提到的,您不需要子查询。

答案 1 :(得分:0)

您没有正确别名表。在你的from语句中,你没有提到表的任何别名,你在选择列中说fid.dat_delib,fid.dat_scad。

但您的查询中没有fid表或别名。

如前所述,不需要子查询,可以直接用子查询编写查询。