count() over() and sum() over() group by

eg:
select t.name,count(*) count1,count(*) over() count2 from test t group by t.name;

本来是想获得每一种name的数量,以及总数量。得到的却不是
仔细看了看 count() over()的用法

count() over() 是统计有多少条

正确写法如下:
select t.name,count(*) count1,sum(count(*)) over() count2 from test t group by t.name;

猜你喜欢

转载自guifan.iteye.com/blog/1582922