Let us first create a table −
mysql> create table DemoTable719 (FirstNumber int,SecondNumber int); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
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)
Display all records from the table using select statement −
mysql> select *from DemoTable719;
This will produce the following output −
+-------------+--------------+ | FirstNumber | SecondNumber | +-------------+--------------+ | 20 | 10 | | 500 | 50 | | 400 | 20 | +-------------+--------------+ 3 rows in set (0.00 sec)
Following is the query to divide numbers from two columns and display result in a new column −
mysql> select *,FirstNumber/SecondNumber AS Result from DemoTable719;
This will produce the following output 7minus;
+-------------+--------------+---------+ | FirstNumber | SecondNumber | Result | +-------------+--------------+---------+ | 20 | 10 | 2.0000 | | 500 | 50 | 10.0000 | | 400 | 20 | 20.0000 | +-------------+--------------+---------+ 3 rows in set (0.00 sec)