# 窗口子句:划分统计函数sum()的应用范围
# over() 将所有查询结果作为一个窗口
# over(rows between 开始位置 and 结束位置)
# 开始位置|结束位置:
# 窗口的第一行: unbounded preceding
# 当前行: current row
# 窗口的内数据的排序 order by
select
profit_id,
profit_date,
profit,
sum(profit)
over(
order by profit_date asc
rows between unbounded preceding and current row
) as cumulative_profit
from daily_profits
order by profit_date asc;

京公网安备 11010502036488号