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
这个结果显然是错误的,这是一个错误还是错误的用法?
答案 0 :(得分:0)
为什么不必要 OVER(PARTITION BY 只使用GROUP BY。
select
day,
count(*) as cnt
from a.table_b
where day between '2017-10-13' and '2017-10-14'
gtoup by day;