汇总总和查询 [英] Roll up sum query

查看:103
本文介绍了汇总总和查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如何汇总SUM 与父母使用TSQL的余额

How to rollup SUM  balance with parent using TSQL

LINE_NO	PARENT  BALANCE
31850	31000	0
31855	31850	0
31860	31855	0
31865	31855	0
31870	31850	0
31875	31870	59115663
31880	31870	279744730
31885	31870	0
31890	31870	0
31895	31870	0
31900	31870	20324000
31920	31850	0
31925	31920	23518942
31930	31920	0


输出量必须









































< td align ="right"style ="">

















































< tbody>












































































LINE_NO PARENT_LINE_NO BALANCE
31850 31000 382703335.22
31855 31850  
31860 31855 0.00
31865 31855 0.00
31870 31850 359184392.94
31875 31870 59115662.90
31880 31870 279744730.10
31885 31870 0.00
31890 31870 0.00
31895 31870 0.00
31900 31870 20323999.94
31920 31850 23518942.28
31925 31920 23518942.28
31930 31920 0.00





















































































OUTPUT SOULD BE




LINE_NO PARENT_LINE_NO BALANCE
31850 31000 382703335.22
31855 31850  
31860 31855 0.00
31865 31855 0.00
31870 31850 359184392.94
31875 31870 59115662.90
31880 31870 279744730.10
31885 31870 0.00
31890 31870 0.00
31895 31870 0.00
31900 31870 20323999.94
31920 31850 23518942.28
31925 31920 23518942.28
31930 31920 0.00











































推荐答案

格林先生,

为了给我们提供测试您的查询和我们的解决方案的工具,请发布:

1)查询创建您的表格,包括索引

  2)查询&NBSP;插入样本数据。

  3)给出样本的预期结果,例如excel的文本或图像。

  4)简短说明业务规则,以及如何获得1-2的结果

  5)您正在使用哪个版本的SQL Server(这将有助于使查询符合您的版本)。

In order to give us the tools to test your query and our solution, please post:
1) Queries to CREATE your table(s) including indexes
 2) Queries  to INSERT sample data.
 3) The desired result given the sample, as text or image of excel for example.
 4) A short description of the business rules, and how you got 1-2 of the results
 5) Which version of SQL Server you are using (this will help to fit the query to your version).

对于上面的示例数据,我不清楚样本数据是真实的样本数据还是所需的输出。能否请您提供更详细的信息?

For the sample data above, I am not clear that the sample data is real sample data or desired output. Could you please provide us more detailed information?

最好的问候,


这篇关于汇总总和查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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