Use the differential as follows to produce team standings that include winning percentage and GB values
mysql>
mysql> CREATE TABLE standings1
-> (
-> team CHAR(20), # team name
-> wins INT, # number of wins
-> losses INT # number of losses
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> INSERT INTO standings1 (team, wins, losses) VALUES ('Winnipeg',37,20);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO standings1 (team, wins, losses) VALUES ('Crookston',31,25);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO standings1 (team, wins, losses) VALUES ('Fargo',30,26);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO standings1 (team, wins, losses) VALUES ('Grand Forks',28,26);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO standings1 (team, wins, losses) VALUES ('Devils Lake',19,31);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO standings1 (team, wins, losses) VALUES ('Cavalier',15,32);
Query OK, 1 row affected (0.00 sec)
mysql>
mysql>
mysql> SELECT team, wins AS W, losses AS L,
-> wins/(wins+losses) AS PCT,
-> (@wl_diff - (wins-losses)) / 2 AS GB
-> FROM standings1
-> ORDER BY wins-losses DESC, PCT DESC;
+-------------+------+------+--------+---------+
| team | W | L | PCT | GB |
+-------------+------+------+--------+---------+
| Winnipeg | 37 | 20 | 0.6491 | 0.0000 |
| Crookston | 31 | 25 | 0.5536 | 5.5000 |
| Fargo | 30 | 26 | 0.5357 | 6.5000 |
| Grand Forks | 28 | 26 | 0.5185 | 7.5000 |
| Devils Lake | 19 | 31 | 0.3800 | 14.5000 |
| Cavalier | 15 | 32 | 0.3191 | 17.0000 |
+-------------+------+------+--------+---------+
6 rows in set (0.00 sec)
mysql>
mysql> drop table standings1;
Query OK, 0 rows affected (0.00 sec)
Related examples in the same category