What does the slash mean in a MySQL query?

MySQLMySQLi Database

The slash means division ( /) in MySQL query. This can be used to divide two numbers. Here, we will see an example to divide numbers from two columns and display result in a new column.

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 perform division with slash in MySQL −

mysql> select *,FirstNumber/SecondNumber AS Result from DemoTable719;

This will produce the following output -

+-------------+--------------+---------+
| FirstNumber | SecondNumber | Result  |
+-------------+--------------+---------+
| 20          | 10           | 2.0000  |
| 500         | 50           | 10.0000 |
| 400         | 20           | 20.0000 |
+-------------+--------------+---------+
3 rows in set (0.00 sec)
raja
Published on 22-Aug-2019 07:19:47
Advertisements