Window函数实现在Postgres SQL中重置的运行总和

时间:2016-03-29 21:16:31

标签: postgresql window-functions

我之前问过这个问题,但唯一的答案非常复杂。我希望有人可以提供更简单的解决方案。这是a link我最初的问题。这是我的数据表:

enter image description here

我使用以下代码获得了该输出:

SELECT date_trunc('day', el.paid_at) as the_day, round(sum(el.amount::numeric/100),0) as amount_raised, sum(round(sum(el.amount::numeric/100),0)) OVER (order by date_trunc('day', el.paid_at)) as sum FROM extended_lineitems el WHERE el.paid_at is not null and el.istip is FALSE GROUP BY the_day ORDER BY the_day 

我希望“sum”列在重置1,000,000时重置。您将在上一个问题的链接中看到用户发布了递归方法。我无法模仿它,并希望有另一种方式。

0 个答案:

没有答案