首页 > 解决方案 > 为什么 Hive 不喜欢这个查询?

问题描述

Ratingshive表是动态分区的Genre,表包含movie_titlesrating of movies

select 100 * stars / total 
  from (select count(rating) as stars 
    from ratingshive 
    where rating = 5) t1, 
  (select count(1) as total 
    from ratingshive) t2

当我在 Hive 中运行上述查询时,我收到此错误 -

FAILED: ParseException line 1:100 missing EOF at ',' near 't1'

标签: hive

解决方案


Hive 不喜欢您的查询很可能是因为旧版本。但是您不需要查询同一个ratingshive表两次然后交叉连接标量结果。使用聚合case

select 100 * count(case when rating=5 then 1 end)/count(*) as rating_percent
  from ratingshive;

推荐阅读