Reputation: 21
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?
Upvotes: 0
Views: 1163
Reputation: 480
$SQL="SELECT *, (Goals+Assists) AS totalPoints FROM stats ORDER BY totalPoints";
Upvotes: 0
Reputation: 726
try this..
$SQL = "SELECT Name, Goals, Assists, (Goals+Assists) AS SumColumn FROM STATUS ORDER BY Points";
Upvotes: 1