蜂巢。通过vs Having-clause进行分区

时间:2017-11-07 04:36:38

标签: hive having-clause

我有以下表格:

column0  column1      column2 column3 column4
sunny    hot         high    false   no
sunny    hot         high    true    no
overcast hot         high    false   yes
rainy    mild        high    false   yes
rainy    cool        normal  false   yes
rainy    cool        normal  true    no

我想用having子句和OVER PARTITION BY运行查询,我的查询是

SELECT column0,column1,column2,count(column0) OVER (PARTITION BY column2) AS cnt FROM FF_weatherdatase1  where column0="sunny"  having cnt>8

但蜂巢显示:

 HAVING specified without GROUP BY error.

请提供方法运行having-clause使用条件超过分区,没有按条件分组,事先感谢。

1 个答案:

答案 0 :(得分:0)

HAVING只能与GROUP BY一起使用。对于您的查询,您可以在括号外使用where条件。

SELECT *
FROM   (SELECT column0,
               column1,
               column2,
               COUNT(column0)
                 OVER (
                   PARTITION BY column2) AS cnt
        FROM   ff_weatherdatase1
        WHERE  column0 = 'sunny') w
WHERE  cnt > 8