使用 OVER 子句和 PARTITION BY 子句使用计数器计算 运行 总计

Calculating Running Total with OVER Clause and PARTITION BY Clause with counter

如何使用计数器计算每个 week_number 和 user_name 点的总和? 我用 sum() OVER (PARTITION BY ORDER BY )

我希望最大总和为 10。
我该怎么做?

这是我的原创table:

这是我想要得到的结果:

这里是 sql 代码:

SELECT week_number,
user_name,
sum(points) OVER (PARTITION BY user_name ORDER BY week_number) AS total_prime
FROM team;

试试这个

select 
  week_number, 
  user_name, 
  points, 
  case when total_prime > 10 then 10 else total_prime end as sum, 
  case when total_prime > 1 and total_prime < 10 then null 
       when total_prime > 10 then total_prime - 10 end as dif
from
  (select 
     week_number, 
     user_name, points, 
     sum(points) over (partition by user_name order by week_number) as total_prime 
   from 
     team) a

我不明白你的第二个 table,其中 alanpoint 4 但有 sum 2