with as insert overwrite table

习惯写sql的时候把insert overwrite table 写在首行,但是在使用with 语法的时候报错:

Error while compiling statement: FAILED: ParseException line 2:0 cannot recognize input near 'with' 't1' 'as' in statement

最初还以为是insert时不支持with语法,后来看with语法的文档时才发现正确用法是:with as xxx (xxx) insert overwrite table select xxx.

原sql:

insert overwrite table iptv_mis_car_registration_ELFV
with  t1 as (select mis,production_month,cnt    from
    iptv_mis_car_registration_CTED )
select 0 as mis,production_month,sum(case when mis>=0 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 1 as mis,production_month,sum(case when mis>=1 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 2 as mis,production_month,sum(case when mis>=2 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 3 as mis,production_month,sum(case when mis>=3 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 4 as mis,production_month,sum(case when mis>=4 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month

修改后的sql:

 

with  t1 as (select mis,production_month,cnt    from
    iptv_mis_car_registration_CTED )
insert overwrite table iptv_mis_car_registration_ELFV
select 0 as mis,production_month,sum(case when mis>=0 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 1 as mis,production_month,sum(case when mis>=1 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 2 as mis,production_month,sum(case when mis>=2 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 3 as mis,production_month,sum(case when mis>=3 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 4 as mis,production_month,sum(case when mis>=4 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 5 as mis,production_month,sum(case when mis>=5 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 6 as mis,production_month,sum(case when mis>=6 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 7 as mis,production_month,sum(case when mis>=7 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 8 as mis,production_month,sum(case when mis>=8 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month union all
select 9 as mis,production_month,sum(case when mis>=9 then cnt else 0 end) cnt  from t1 GROUP BY production_month  ORDER BY production_month

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值