hive basic group by and over(partition by)函数遇到错误

nbewdwxp  于 2021-06-01  发布在  Hadoop
关注(0)|答案(1)|浏览(320)
select
    day,
    count(*) OVER(PARTITION BY day) as cnt
from a.table_b
where day between '2017-10-13' and '2017-10-14';

查询结果如下:

day        cnt
2017-10-13  12
2017-10-13  12
2017-10-14  13
2017-10-14  13

但是,使用group by对此结果进行分组时,

select day, cnt
from 
(
    select day, count(*) OVER(PARTITION BY day) as cnt 
    from a.table_b 
    where day between '2017-10-13' and '2017-10-14'
) t
group by day, cnt;

结果如下:

2017-10-13  1
2017-10-14  1

这个结果显然是错误的,这是一个错误还是错误的用法?

euoag5mw

euoag5mw1#

为什么只使用groupby就不必要的over(分区)。

select
    day,
    count(*) as cnt
from a.table_b
where day between '2017-10-13' and '2017-10-14'
group by  day;

相关问题