0

Is it possible to use MySql SUM() function inside another MySql SUM() function ??

Like below

$query="SELECT SUM(Table1.Column1+SUM(Table2.Column2+Table2.Column3)) 
        from Table1 LEFT JOIN Table2 ON Table1.id = Table2.table1_id 
        WHERE Table1.Column2='Test'";

Thanks

2
  • Do you have an error? Commented Feb 18, 2014 at 7:58
  • SELECT SUM(foo) + SUM(bar) as foobar ? Commented Feb 18, 2014 at 8:00

2 Answers 2

2

You just need one SUM():

SELECT SUM(Table1.Column1 + Table2.Column2 + Table2.Column3) ...

Or use SUM() on each field:

SELECT SUM(Table1.Column1) + SUM(Table2.Column2) + SUM(Table2.Column3) ...
Sign up to request clarification or add additional context in comments.

Comments

0

From basic math a + b + c = a + (b + c)

So just use one sum. It will be equivalent with what you are doing there ..

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.