[Solved] SQL Server : how to sum? [closed]


SELECT SUM(Value) FROM TableName;

Using a GROUP BY (per your comment above) is when you want things grouped over a subset. In this case, a group by would return the same info you’ve sampled, because there’s no groups to sum on the desc field… however if you had two “e” descriptions (let’s say 40 for each) and you used the following:

SELECT [Desc], SUM(Value) FROM TableName GROUP BY [Desc];

You would get a sum for each group of “desc”s, with the ‘e’ group showing 80 (as it sums the two values found within the unique group you’ve specified)

Also note that Desc is a reserved word (meaning DESCENDING, for sort orders), if that’s your actual field name.

solved SQL Server : how to sum? [closed]