sql - SAS SQL - 如何获得过去 X 个月的累积总和
问题描述
我有一张这样的桌子:
我想根据 date_ini 和今天计算过去 x 个月中每个 cust_id 列“total”的累积总和,所以我的输出是:
你能帮我在 sas / proc sql 中做这个吗?
谢谢!
解决方案
看起来您想使用 CASE 来决定 TOTAL 是否有助于您的新总和。
因此,假设您的参考日期是当前日期,您可能会使用这样的日期。
create table want as
select cust_id
, sum(case
when (date_ini >= intnx('month',today(),-1,'b') then total
else 0 end) as total_last_month
, sum(case
when (date_ini >= intnx('month',today(),-36,'b') then total
else 0 end) as total_last_36months
from have
group by cust_id
;
但我不确定我是否会称这些累积总和。
推荐阅读
- json - 将数据从动态创建的字段发送到控制器
- reactjs - 直接在类 react-redux 中编写调度函数
- c - 如何使用 sscanf 提取子字符串?
- python - num+=i>num 行后面的逻辑是什么
- firebase - 如何在 Flutter 中启用/禁用 Firebase Crashlytics
- reactjs - 如何使用 .map 函数评估 React 中对象中的每个值
- database - Structuring of data for users in firebase
- php - php将关联数值数组转换为普通数组
- git - Git不断复制文件并在文件名末尾附加'2'
- python - 如何根据物品消耗找到物品生命周期?