PDA

View Full Version : Is it possible to sum the values of multiple fields on a single SQL record?


BigToque
02-15-2005, 09:50 PM
I have fields for Goals and Assists.

I want to take those 2 fields and sum them to make a 3rd field PTS, then send them to variable in my PHP code to be printed to the screen.

My statement is this:

SELECT player_stats.G, player_stats.A, SUM (player_stats.G + player_stats.A) PTS
FROM player_stats
WHERE player_stats.PID =10
AND player_stats.season =1

The statement breaks with the bolded part.

raf
02-15-2005, 10:09 PM
SELECT player_stats.G, player_stats.A, (player_stats.G + player_stats.A) AS PTS
FROM player_stats
WHERE player_stats.PID =10
AND player_stats.season =1

BigToque
02-15-2005, 10:24 PM
That worked. Thanks a lot!

raf
02-15-2005, 10:28 PM
You're welcome :thumbsup:

Librarian
03-14-2005, 04:25 PM
If you have the display set up in a table with three columns, player_stats.G and player_stats.A and PTS you can sort by the first two fields using <a href='PageName.asp?sort=FieldName'>. How would you sort by the new variable?

Kiwi
03-15-2005, 01:01 AM
SELECT player_stats.G, player_stats.A, (player_stats.G + player_stats.A) AS PTS
FROM player_stats
WHERE player_stats.PID =10
AND player_stats.season =1
ORDER BY PTS