【问题标题】:hive select count based on average of count蜂巢根据计数的平均值选择计数
【发布时间】:2017-04-13 21:17:57
【问题描述】:

您好,我正在尝试使用以下 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' '(' 附近的输入

【问题讨论】:

    标签: hadoop hive


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 2016-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多