在hive中创建表时出错

时间:2017-03-01 13:49:11

标签: sql hive

我的查询是

with subs2 as(
  Select columns
  from t1
  right join t2
  on conditions
)
CREATE TABLE new_n row format delimited fields terminated by '|' STORED AS RCFile AS
Select columns
from subs2
left join charge2
on conditions
where conditions;

我得到的错误看起来像这样

cannot recognize input near 'CREATE' 'TABLE' 'new_n' in statement.

为什么会这样?

1 个答案:

答案 0 :(得分:0)

我认为withselect一致。所以试试这个:

CREATE TABLE new_n row format delimited fields terminated by '|' STORED AS RCFile AS
    with subs2 as (
      Select columns
      from t1
      right join t2
      on conditions
    )
    Select columns
    from subs2 left join
          charge2
          on conditions
    where conditions;

或者,您可以在没有with

的情况下重写
CREATE TABLE new_n row format delimited fields terminated by '|' STORED AS RCFile AS
    Select columns
    from (Select columns
           from t2 left join  -- I much prefer `left join`
           t1
           on conditions
          ) subs2 left join
          charge2
          on conditions
    where conditions;