How to find sum of multiple columns in a table in SQL Server 2005?

后端 未结 8 1979
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 17:13

I have a table Emp which has these rows:

Emp_cd | Val1  | Val2  | Val3  | Total
-------+-------+-------+-------+-------
 1     | 1.23  | 2.23  |         


        
8条回答
  •  伪装坚强ぢ
    2020-12-04 17:49

    Easy:

    SELECT 
       Val1,
       Val2,
       Val3,
       (Val1 + Val2 + Val3) as 'Total'
    FROM Emp
    

    or if you just want one row:

    SELECT 
       SUM(Val1) as 'Val1',
       SUM(Val2) as 'Val2',
       SUM(Val3) as 'Val3',
       (SUM(Val1) + SUM(Val2) + SUM(Val3)) as 'Total'
    FROM Emp
    

提交回复
热议问题