如何在sql server表行中对数据进行求和 [英] How to sum data's in sql server table rows

查看:630
本文介绍了如何在sql server表行中对数据进行求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,祝大家节日快乐,



我正在为我的组织在月度汇总数据库上写一个项目我有一张表,我分成三个表我想要汇总所有行以形成一个Grand Total,我将在仪表板上显示,其样本如下:



Hello every one Happy holiday to all,

I am writing a project for my organisation on monthly aggregate database i have a table that i split into three table i want to sum all the rows to form a Grand Total which i am to display on the dashboard, sample of it is as below :

select * from tbl_htc1 a join tbl_htc2 b on a.years = b.years join tbl_htc3 c on b.years = c.years
where a.years = b.years and b.years = c.years





高于我用来加入三个表的SQL语句,我需要所有的行将数据汇总在一起并返回我将在应用程序仪表板上显示的总计。



任何他lp将受到赞赏,因为对我来说非常紧急



谢谢大家,上帝保佑



以上是将三个表连接在一起的sql语句,但我想总结所有行以获得所有行的总和。



above the SQL statement I used to join the three tables, i need all the rows data's to be sum together and return the grand Total this i will display on the application dashboard.

any help will be appreciated as the is so urgent for me

thank you all and God bless

above is the sql statement to join the three table together, but i want to sum all the rows to get the Total sum of all the rows.

推荐答案

最简单的方法是联合表并总结结果



例如



The easiest way would be to union the tables and sum the result

eg

Select Sum(a) from (
Select Sum(field) as a from tableA
union all
Select Sum(field) as a from tableb
union all
Select sum(field) as a from tablec)as T





从每个select语句中,您可以添加所需的任何过滤器。 />


请参阅 SQL联盟 [ ^ ]


这篇关于如何在sql server表行中对数据进行求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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