【问题标题】:How to use Max function on the output of count fucnction in Hive如何在 Hive 中计数函数的输出上使用 Max 函数
【发布时间】:2016-03-26 16:09:59
【问题描述】:

如何在Count 函数的输出上使用Max 函数。我有一个表candidates,其列为candidatenames,如下所示

AAA  
BBB
CCC
BBB
AAA
FFF
AAA
AAA

我想要输出如下:

AAA 4

自从AAA 出现最多次数4。如何在 hive 中获取此输出?

【问题讨论】:

标签: mapreduce hive


【解决方案1】:

您可以使用 Hive 窗口函数来做到这一点;你可以阅读他们here

查询

select candidates, c
from (
    select candidates, c
        , max(c) over () max_c
    from (
        select candidates, count(*) c
        from db.table
        group by candidates ) x
    ) y
where max_c = c

输出

candidates    c
AAA           4

【讨论】:

    猜你喜欢
    • 2021-04-02
    • 1970-01-01
    • 1970-01-01
    • 2016-12-27
    • 1970-01-01
    • 2019-05-18
    • 2021-09-24
    • 1970-01-01
    • 2020-05-05
    相关资源
    最近更新 更多