首页 > 代码库 > hive union all报错
hive union all报错
今天在写一个sql的时候,使用了hive的union all,运行时报错。
sql如下:
select dimension_name,dt,dtype_name,uv,new_uv,old_uv,pv,stay_time from temp_bi.uv union all select ‘平台‘ dimension_name ,dt ,app_platform dtype_name ,count(distinct mid) uv ,count(distinct case when is_new = 1 then mid end) new_uv ,count(distinct case when is_new = 0 then mid end) old_uv ,sum(pv_num) pv ,sum(stay_time) stay_time --停留时长(秒) from vipdw.dw_log_app_visit_ds1 where dt between get_dt_date(get_date(-1)) and get_dt_date(get_date(-1)) group by ‘平台‘ ,dt ,app_platform
报错信息如下:
FAILED: SemanticException 1:71 Top level UNION is not supported currently; use a subquery for the UNION. Error encountered near token ‘app_platform‘
hive不支持顶层的union all,使用子查询来解决即可:
select * from ( select dimension_name,dt,dtype_name,uv,new_uv,old_uv,pv,stay_time from temp_bi.uv union all select ‘平台‘ dimension_name ,dt ,app_platform dtype_name ,count(distinct mid) uv ,count(distinct case when is_new = 1 then mid end) new_uv ,count(distinct case when is_new = 0 then mid end) old_uv ,sum(pv_num) pv ,sum(stay_time) stay_time --停留时长(秒) from vipdw.dw_log_app_visit_ds1 where dt between get_dt_date(get_date(-1)) and get_dt_date(get_date(-1)) group by ‘平台‘ ,dt ,app_platform) a
本文出自 “菜光光的博客” 博客,请务必保留此出处http://caiguangguang.blog.51cto.com/1652935/1414086
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。