从两列中除以数字,并在MySQL的新列中显示结果
让我们首先创建一个表-
mysql> create table DemoTable719 (FirstNumber int,SecondNumber int);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable719 values(20,10); mysql> insert into DemoTable719 values(500,50); mysql> insert into DemoTable719 values(400,20);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable719;
这将产生以下输出-
+-------------+--------------+ | FirstNumber | SecondNumber | +-------------+--------------+ | 20 | 10 | | 500 | 50 | | 400 | 20 | +-------------+--------------+ 3 rows in set (0.00 sec)
以下是将数字分为两列并在新列中显示结果的查询-
mysql> select *,FirstNumber/SecondNumber AS Result from DemoTable719;
这将产生以下输出7min;
+-------------+--------------+---------+ | FirstNumber | SecondNumber | Result | +-------------+--------------+---------+ | 20 | 10 | 2.0000 | | 500 | 50 | 10.0000 | | 400 | 20 | 20.0000 | +-------------+--------------+---------+ 3 rows in set (0.00 sec)