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
这个结果显然是错误的,这是一个错误还是错误的用法?
1条答案
按热度按时间euoag5mw1#
为什么只使用groupby就不必要的over(分区)。