解释我需要什么的最好方法是展示,所以,这里是:
目前我有这个问题
select
date_
,count(*) as count_
from table
group by date_
它将返回以下数据库
现在我需要得到一个新的列,它显示了所有前7天的计数,考虑到行日期。因此,如果该行是从第29/06天开始的,那么我必须计算该天的所有ocurrence(我的查询已经在这样做了),并获取从第22/06天到第29/06天的所有ocurrence
结果应该是这样的:
解释我需要什么的最好方法是展示,所以,这里是:
目前我有这个问题
select
date_
,count(*) as count_
from table
group by date_
它将返回以下数据库
现在我需要得到一个新的列,它显示了所有前7天的计数,考虑到行日期。因此,如果该行是从第29/06天开始的,那么我必须计算该天的所有ocurrence(我的查询已经在这样做了),并获取从第22/06天到第29/06天的所有ocurrence
结果应该是这样的:
4条答案
按热度按时间zte4gxcn1#
如果所有日期都有值,且没有间隔,则可以将窗口函数与
rows
框架:m528fe3b2#
您可以尝试以下方法:
ejk8hzay3#
如果存在间隙,则可以执行更复杂的解决方案,在其中添加和减去值:
这个
- sum(count_)
是因为你似乎不想在当天的累计金额。你也可以使用讨厌的自连接方法。7天内都可以:
随着“7”越来越大,性能会越来越差。
iugsix8n4#
尝试使用新列的子查询: