Reputation: 103
I have a table in my database with two columns as int for example cal1
and cal2
.
I make the sum from each row as in select ( cal1 + cal2) from cat as total
, now I want to do the sum from all columns total if is possible.
Upvotes: 0
Views: 4602
Reputation: 432180
You want 2 totals in one go?
SELECT
cal1+cal2 AS PerRowTotal,
SUM(cal1+cal2) OVER () AS AllRowTotal
FROM
cat
Upvotes: 0
Reputation: 35907
You can do the addition in the SUM :
SELECT SUM(cal1+cal2) AS total
FROM cat
Upvotes: 2
Reputation: 43209
SELECT (SUM(cal1) + SUM(cal2)) AS TotalSum FROM cat
Thats to sum the values of all rows together. If you want to sum all columns up, you have to specifically write their names into the column list.
Upvotes: 0