关于计算年内按月累计值的SQL语句的写法
答案:5 悬赏:70 手机版
解决时间 2021-01-17 14:59
- 提问者网友:爱唱彩虹
- 2021-01-17 06:35
关于计算年内按月累计值的SQL语句的写法
最佳答案
- 五星知识达人网友:掌灯师
- 2021-01-17 07:48
1> select * from TEST_zfh521;
2> go
month value
----------- -----------
1 6
2 10
3 9
(3 行受影响)
1> SELECt
2> month,
3> (SELECT SUM(value) FROM TEST_zfh521 as T WHERe t.month <= TEST_zfh521.month) AS all_val
4> FROM
5> TEST_zfh521
6> GROUP BY
7> month;
8> go
month all_val
----------- -----------
1 6
2 16
3 25
(3 行受影响)
2> go
month value
----------- -----------
1 6
2 10
3 9
(3 行受影响)
1> SELECt
2> month,
3> (SELECT SUM(value) FROM TEST_zfh521 as T WHERe t.month <= TEST_zfh521.month) AS all_val
4> FROM
5> TEST_zfh521
6> GROUP BY
7> month;
8> go
month all_val
----------- -----------
1 6
2 16
3 25
(3 行受影响)
全部回答
- 1楼网友:骨子里都是戏
- 2021-01-17 12:12
这么麻烦的东西,为什么要用SQL写呢。。。读出来用程序语言写
- 2楼网友:老鼠爱大米
- 2021-01-17 10:42
新建一个表了,每次月底更新一下,吧数据导进去
- 3楼网友:酒者煙囻
- 2021-01-17 10:28
select b.month,sum(a.value)
from #t a,#t b
where a.month<=b.month
group by b.month
from #t a,#t b
where a.month<=b.month
group by b.month
- 4楼网友:躲不过心动
- 2021-01-17 09:11
假设表名为table1
select a.month,sum(b.value)from table1 a,table1 b where a.month>=b.month
group by a.month
select a.month,sum(b.value)from table1 a,table1 b where a.month>=b.month
group by a.month
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯