Set a variable specifically.
mysql>
mysql>
mysql> CREATE TABLE sales (
-> code int(11) default NULL,
-> sales_rep int(11) default NULL,
-> customer int(11) default NULL,
-> value int(11) default NULL
-> ) ;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> INSERT INTO sales VALUES (1, 1, 1, 2000);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO sales VALUES (2, 4, 3, 250);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO sales VALUES (3, 2, 3, 500);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO sales VALUES (4, 1, 4, 450);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO sales VALUES (5, 3, 1, 3800);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO sales VALUES (6, 1, 2, 500);
Query OK, 1 row affected (0.00 sec)
mysql>
mysql> SET @result = 22/7*33.23;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> SELECT @result;
+-----------------+
| @result |
+-----------------+
| 104.43714282866 |
+-----------------+
1 row in set (0.00 sec)
mysql>
mysql>
mysql> SET @t = 'sales';
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> SET @d=2000;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> SELECT @d,value FROM sales WHERE value>@d;
+------+-------+
| @d | value |
+------+-------+
| 2000 | 3800 |
+------+-------+
1 row in set (0.00 sec)
mysql>
mysql> SELECT @e,value FROM sales WHERE value>(@e:=2000);
+------+-------+
| @e | value |
+------+-------+
| NULL | 3800 |
+------+-------+
1 row in set (0.00 sec)
mysql>
mysql> SELECT @f:=2000,value FROM sales WHERE value>(@f:=2000);
+----------+-------+
| @f:=2000 | value |
+----------+-------+
| 2000 | 3800 |
+----------+-------+
1 row in set (0.00 sec)
mysql>
mysql> drop table sales;
Query OK, 0 rows affected (0.00 sec)
mysql>
Related examples in the same category