0

I have three MySQL columns, Name, Goals, Assists (G and A respectively). I want to calculate points by adding Goals and Assists together, and then sort Names by points.

What I tried was;

$SQL="SELECT * FROM stats WHERE Points=G+A ORDER BY Points";

This didn't work, does anyone have any suggestions on basic addition in MySQL using integers from separate columns?

0

3 Answers 3

1

try this..

$SQL = "SELECT Name, Goals, Assists, (Goals+Assists) AS SumColumn FROM STATUS ORDER BY Points";
Sign up to request clarification or add additional context in comments.

Comments

0

SELECT name, (G+A) AS points FROM stats ORDER BY points

1 Comment

Getting syntax errors, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT name, (G+A) AS points ORDER BY points' at line 1
0
$SQL="SELECT *, (Goals+Assists) AS totalPoints FROM stats ORDER BY totalPoints";

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.