紧急构建SQL查询 [英] Build SQL Query Urgent

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

问题描述

构建Sql查询我们有一个包含三列的Sql表Viz Name_of_ffice,Month,Amount





 Name_Of_Office月份金额
DivisionBhopal 04 125
DivisionBhopal 05 50
DivisionBhopal 06 100
DivisionBhopal 10 125
DivisionSagar 04 600
DivisionSagar 05 520
DivisionSagar 06 400
DivisionSagar 10 100





财政年度月我们应该采取计算。通过公式总是开始从4月到选定的月份假设用户将选择月份6月(从下拉列表)计算应该像这样执行



 Name_Of_Office总计上个月当前月总金额
DivisionBhopa 4月+ 5月6月4月+ 5月+ 6月
DivisionSagar 4月+ 5月6月4月+ 5月+ 6月





这里我们不会添加oct金额因为选定月份是6月我们想要数据直到6月



六月份数据应该看起来像

 Name_Of_Office总计上个月当前月总金额
DivisionBhopal 175 100 275
DivisionSagar 1120 400 1520





10月份数据应如下(如果用户选择12月)

 Name_Of_Office总计上个月当月总计金额
DivisionBhopal 275 125 400
Divisionsagar 1520 100 1620

解决方
我们不会做你的功课:它被设置的一个原因。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但是我们不会为你做这一切!


你需要的只是:运行金额 [ ^ ]或运行总计 [ ^ ]



如何实现?请阅读:计算SQL Server中的简单运行总计 [ ^

Build Sql Query We have a Sql Table Having Three Columns Viz Name_of_ffice , Month , Amount


Name_Of_Office	Month	Amount
DivisionBhopal	04	125
DivisionBhopal	05	50
DivisionBhopal	06	100
DivisionBhopal	10	125
DivisionSagar	04	600
DivisionSagar	05	520
DivisionSagar	06	400
DivisionSagar	10	100



FINANCIAL Year Month Should We Taken For Calculation . By the Formula Always Start sum From April to Selected Month Suppose User will Select Month June (from dropdown) Calculation Should be Performed Like this

Name_Of_Office	Sum Upto Previous Month	Present Month 	Total Amount
DivisionBhopa	April + May	June	April + May+ June
DivisionSagar	April + May	June	April + May+ June



Here we will not add oct Amount because Selected Month is June we want data till june

For June Month Data Should look like

Name_Of_Office	Sum Upto Previous Month	Present Month	Total Amount
DivisionBhopal	175		100	275
DivisionSagar	1120	400	1520



For October Month Data Should look like (If User Select December)

Name_Of_Office	Sum Upto Previous Month	Present Month	Total Amount
DivisionBhopal	275		125	400
Divisionsagar	1520	100	1620

解决方案

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


All you need is called: running sum[^] or running total[^]

How to achieve that? Please, read this: Calculating simple running totals in SQL Server[^]


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

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