sql - 查询毫秒访问中的增量值
问题描述
我正在做一个查询,显示按月份分组的值、它们的计数和它们的值,如下所示:
Month count value
1 7 480€
2 8 500€
3 3 250€
我希望它包含这样的增量值:
Month count value incr. incr. val
1 7 480€ 7 480€
2 8 500€ 15 980€
3 3 250€ 18 1230€
我根本做不到。我就是不能还是有办法?
解决方案
有趣的值在 MS Access 中有点麻烦,但您可以使用相关子查询来计算它:
select t.*,
(select sum(t2.count)
from t as t2
where t2.month <= t.month
) as running_count,
(select sum(t2.value)
from t as t2
where t2.month <= t.month
) as running_value
from t;
推荐阅读
- python - 如何在实例化对象时传递 **kwargs 并在类的 __init__() 方法中访问它
- r - ggplot2:当data.frame中有NA值时,如何摆脱带有空图例的geom_point冗余颜色代码?
- react-hooks - 反应钩子 - 无法读取未定义的属性映射
- python-3.x - 异步不和谐机器人中的时间不一致
- postgresql - 使用spring data rest与postgresql和缓存作为redis
- c++ - 0-1 背包 C++ 没有返回正确的值
- android - 如何在适配器类的 onBindViewHolder 中绑定整数值
- java - 使用 Java 中的流和 lambda 使用 for 循环重写笛卡尔积
- kotlin - 有没有办法在 Ktor 中热重载静态文件?
- jquery - 被另一个 masterrow 剑道网格折叠时仍选择上一个 masterrow