我正在使用Hadoop的0.X版本。此版本不允许子查询。有人可以帮助我将下面的SQL转换为不使用子查询。
select 100 * stars / total from
(select count(rating) as stars
from ratingshive
where rating = 5) t1,
(select count(1) as total
from ratingshive) t2
答案 0 :(得分:0)
您需要条件聚合。 (还要注意,计算列别名不能在同一查询中使用。)
select 100 * sum(cast(rating=5 as int)) / count(*)
from ratingshive