To find a value and save it in a variable
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.00 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> SELECT @wl_diff := MAX(wins-losses) FROM standings1;
+------------------------------+
| @wl_diff := MAX(wins-losses) |
+------------------------------+
| 17 |
+------------------------------+
1 row in set (0.00 sec)
mysql>
mysql> drop table standings1;
Query OK, 0 rows affected (0.00 sec)
Related examples in the same category