hive根据计数的平均值选择计数

时间:2017-04-13 21:17:57

标签: hadoop hive

您好我正在尝试使用以下hive语句找到高于平均值的计数

Select x, Count(x) as y from data  

group by x

Having Count(x) >= (select Avg(z.count1) as aveg 
                    from (select x, Count(x) as count1 from data group by x ) z) ;

我收到错误,因为ParseException第1:87行无法识别'Select''Avg''附近的输入(''在表达式规范中

1 个答案:

答案 0 :(得分:0)

select      x
           ,cnt_x

from       (select      x
                       ,count(x)                as cnt_x
                       ,avg (count(x)) over ()  as avg_cnt_x

            from        data  

            group by    x
            ) t

where       cnt_x >= avg_cnt_x