将选定的总计添加到另一个总计SQL Server 2008中 [英] Adding selected totals to another total SQL server 2008

查看:47
本文介绍了将选定的总计添加到另一个总计SQL Server 2008中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的数据库输出如下所示:
-------------------------------------------------- -------------
客户| TotalMonth1 | totalMonth2 | TotalMonth3 | TotalCurrent
-------------------------------------------------- -------------
保罗| R 2012.02 | R 2021.03 | R 205411.99 | R 12004.52 |


现在,我想在select语句上添加一列,以添加TotalMonth1,totalMonth2,TotalMonth3的月份总数.

所以像

  SELECT  SUM(TotalMonth1 + totalMonth2 + TotalMonth3) as  TotalLastMonths 


有任何建议吗?

解决方案

  select  Client,TotalMonth1,totalMonth2,TotalMonth3 ,totalcurrent,SUM(TotalMonth1 + totalMonth2 + TotalMonth3) as  TotalLastMonths  from  table1 


Hi
My database output looks as follows :
---------------------------------------------------------------
Client | TotalMonth1 | totalMonth2 | TotalMonth3 | TotalCurrent
---------------------------------------------------------------
Paul | R 2012.02 | R 2021.03 | R 205411.99 | R 12004.52 |


Now I want to add a column on the select statement that adds the totals of the month for TotalMonth1, totalMonth2, TotalMonth3.

so something like

SELECT SUM(TotalMonth1 + totalMonth2 +  TotalMonth3) as TotalLastMonths 


any suggestions?

解决方案

select Client,TotalMonth1, totalMonth2 , TotalMonth3,totalcurrent, SUM(TotalMonth1 + totalMonth2 +  TotalMonth3) as TotalLastMonths from table1


这篇关于将选定的总计添加到另一个总计SQL Server 2008中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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