34,593
社区成员
发帖
与我相关
我的任务
分享
create table ttx(id int, v int)
insert into ttx
select 1,5
union all select 1,2
union all select 2,3
union all select 2,8
union all select 1,3
union all select 2,6
--group by的用法
select id,
sum(v) as sum_v
from ttx
group by id
/*
id sum_v
1 10
2 17
*/
--over(partition by )的用法
select id,
v,
sum(v) over(partition by id) as sum_v
from ttx
/*
id v sum_v
1 5 10
1 2 10
1 3 10
2 6 17
2 3 17
2 8 17
*/