Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I compute the PCT and GB for a league based on Wins and Losses

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
Hi All,

I have a table with wins and losses. When I select the data I would like to calculate pct (win percentage) and gb (games behind).

My schema is table SCRECORDS, fields: NAME (varchar), WINS(int), LOSSES(int)

I found a query like this but it seems broken.
Code:
SELECT @wl_diff = MAX(WINS-LOSSES) FROM SCRECORDS;
SELECT NAME, WINS AS W, LOSSES AS L, WIN(WINS+LOSSES) AS PCT,
(@wl_diff - (WIN-LOSS))  2 AS GB	
FROM SCRECORDS
ORDER BY WINS-LOSSES DESC, PCT DESC;

Thanks!
 
I got the pct to work with this query
Code:
SELECT NAME, WINS AS W, LOSSES AS L,
TRUNCATE(WINS/(WINS+LOSSES),3) AS PCT,
IF((@wl_diff - (WINS-LOSSES)) = 0,'-',(@wl_diff - (WINS-LOSSES))/2) AS GB
FROM screcords
ORDER BY WINS-LOSSES DESC, PCT DESC;

but GB is all null
Any suggestions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top