0

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.

1
  • From all new rows total Commented Jul 31, 2011 at 17:52

3 Answers 3

2

You can do the addition in the SUM :

SELECT SUM(cal1+cal2) AS total
  FROM cat
Sign up to request clarification or add additional context in comments.

3 Comments

@naf-naf: are you sure this does what you want? I thought you wanted per row and the SUM of all rows in one go?
@naf-naf: who was that last comment for? Use the @ thing if me please. See my answer too
gbn, this does exactly what you describe. Edit: Sorry, I misunderstood your post (realized this after seeing your answer). You are probably right.
0
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.

1 Comment

I need to know each row alone, and also the all rows from the to collumns, With this example it does not work
0

You want 2 totals in one go?

SELECT
   cal1+cal2 AS PerRowTotal,
   SUM(cal1+cal2) OVER () AS AllRowTotal
FROM
   cat

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.