使用sql server中的视图累计数量 [英] Acumulated amount using view in sql server

查看:286
本文介绍了使用sql server中的视图累计数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问如何使用视图实现这个目标

i有此表A



month | amt

1月10日

2月20日

3月12日

apr 34



我想要这个像这样的视频



月| amt |累积amt

1月10日10

2月20日30

3月12日42

apr 34 76



我如何从第一个月开始添加到上个月显示每个Acummulated amt

i在视图中使用了这个代码但它没有用

pls how can i achieve this using a view
i have this table A

month |amt
Jan 10
Feb 20
Mar 12
apr 34

I want this in a veiw like this

month |amt |Acumulated amt
Jan 10 10
Feb 20 30
Mar 12 42
apr 34 76

how do i add from the first month comming down to the last month an showing each Acummulated amt
i have used this code in a view but it does no work

SELECT DISTINCT MONTH, Amt, Amt + Amt AS bb
FROM         dbo.A
WHERE     (MONTH <= MONTH)
ORDER BY MONTH<code></code>

推荐答案

查看关于运行总计的这篇文章。



http://geekswithblogs.net /Rhames/archive/2008/10/28/calculating-running-totals-in-sql-server-2005---the-optimal.aspx [ ^ ]



你需要真正做自我加入。基本上引用你的表两次,并链接表一个月小于表b月的月份并一起添加a和b金额。
Look at this article on running totals.

http://geekswithblogs.net/Rhames/archive/2008/10/28/calculating-running-totals-in-sql-server-2005---the-optimal.aspx[^]

You need to really to do self joins. Basically reference your table twice, and link on the month where table a month is less than table b month and add a and b amount together.


这篇关于使用sql server中的视图累计数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆