John AJ
John AJ

Reputation: 21

Addition in MySQL using information from columns to create a variable?

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

Answers (3)

Semi-Friends
Semi-Friends

Reputation: 480

$SQL="SELECT *, (Goals+Assists) AS totalPoints FROM stats ORDER BY totalPoints";

Upvotes: 0

apoq
apoq

Reputation: 1454

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

Upvotes: 0

KethanKumar
KethanKumar

Reputation: 726

try this..

$SQL = "SELECT Name, Goals, Assists, (Goals+Assists) AS SumColumn FROM STATUS ORDER BY Points";

Upvotes: 1

Related Questions