让我们首先创建一个表-
mysql> create table DemoTable1483 -> ( -> Salary int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1483 values(100); mysql> insert into DemoTable1483 values(500); mysql> insert into DemoTable1483 values(400);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1483;
这将产生以下输出-
+--------+ | Salary | +--------+ | 100 | | 500 | | 400 | +--------+ 3 rows in set (0.00 sec)
以下是执行选择用户定义变量的查询-
mysql> select sum(Salary) into @TotalSalary from DemoTable1483;
现在显示变量的值-
mysql> select @TotalSalary;
这将产生以下输出-
+--------------+ | @TotalSalary | +--------------+ | 1000 | +--------------+ 1 row in set (0.00 sec)