Hive为什么不喜欢此查询?

时间:2018-07-15 03:15:31

标签: 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'

1 个答案:

答案 0 :(得分:0)

Hive最不喜欢您的查询,因为它是旧版本。但是,您无需两次查询相同的ratingshive表,然后交叉连接标量结果。将聚合与case一起使用:

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