Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Come trovare la somma di più colonne in una tabella in SQL Server 2005?

Facile:

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

o se vuoi solo una riga:

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