查询选定的记录和总计 [英] Query for selected records and total
本文介绍了查询选定的记录和总计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
我有一张桌子,有这样的记录
身份证金额
1100
2 500
3 1500
4 5800
现在我想获得类似
的记录
1100100
2500600
3 1500 2100
4 5800 7900
任何人都可以帮助我进行此查询以获取这样的记录... !!
谢谢大家... !!
解决方案
在这里查看运行中的示例示例
http://www.techrepublic.com/article/running-totals-in- sql-server-queries/6158593 [ ^ ]
或此处的代码项目文章
在SQL Server中计算简单运行总计 [ ^ ]
插入 插入 @ t 选择 1 , 10 联盟 选择 2 , 12 联盟 选择 3 , 3 联盟 选择 4 , 15 联盟 选择 5 , 23 选择 * 来自 @ t 选择 t1.id,t1.SomeNumt,SUM(t2.SomeNumt) as sum 来自 @ t t1 内部 加入 @ t t2 在上t1.id> = t2.id 组 依据 t1.id,t1.SomeNumt 订单 通过 t1.id
谢谢
如果您只需要在T-SQL中运行总计,请从此处开始: http://www.sqlhacks.com/Summary/Running_Total [ ^ ].
hello friends,
i have one table and there is record like that
ID Amount
1 100
2 500
3 1500
4 5800
now i want to get record like
1 100 100
2 500 600
3 1500 2100
4 5800 7900
can any one help me for this query to get record like this...!!
Thank You all...!!
解决方案
Have a look here for a running total example
http://www.techrepublic.com/article/running-totals-in-sql-server-queries/6158593[^]
Or a code project article here
Calculating simple running totals in SQL Server[^]
insert into @t select 1,10 union select 2,12 union select 3,3 union select 4,15 union select 5,23 select * from @t select t1.id, t1.SomeNumt, SUM(t2.SomeNumt) as sum from @t t1 inner join @t t2 on t1.id >= t2.id group by t1.id, t1.SomeNumt order by t1.id
Thanks
If you need running totals in just T-SQL, start from here: http://www.sqlhacks.com/Summary/Running_Total[^].
这篇关于查询选定的记录和总计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文