
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Divide Numbers from Two Columns in MySQL
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)
Advertisements