用 MySQL 将两列数字相除,并将结果显示在新列中
让我们首先创建一个表 −
mysql> create table DemoTable719 (FirstNumber int,SecondNumber int); Query OK, 0 rows affected (0.57 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable719 values(20,10); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable719 values(500,50); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable719 values(400,20); Query OK, 1 row affected (0.11 sec)
使用 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;
这将生成以下输出 7minus;
+-------------+--------------+---------+ | FirstNumber | SecondNumber | Result | +-------------+--------------+---------+ | 20 | 10 | 2.0000 | | 500 | 50 | 10.0000 | | 400 | 20 | 20.0000 | +-------------+--------------+---------+ 3 rows in set (0.00 sec)
广告