
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Query to divide the values of two columns and display the result in a new column using MySQL wildcard?
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value1 int, Value2 int ); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Value1,Value2) values(100,150); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Value1,Value2) values(500,1000); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(Value1,Value2) values(15000,18000); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+--------+--------+ | Id | Value1 | Value2 | +----+--------+--------+ | 1 | 100 | 150 | | 2 | 500 | 1000 | | 3 | 15000 | 18000 | +----+--------+--------+ 3 rows in set (0.00 sec)
Let us now divide the values from two columns and display the result in a new column with MySQL wildcards −
mysql> select *,(Value1/Value2) AS Result from DemoTable;
This will produce the following output −
+----+--------+--------+--------+ | Id | Value1 | Value2 | Result | +----+--------+--------+--------+ | 1 | 100 | 150 | 0.6667 | | 2 | 500 | 1000 | 0.5000 | | 3 | 15000 | 18000 | 0.8333 | +----+--------+--------+--------+ 3 rows in set (0.00 sec)
- Related Articles
- Divide numbers from two columns and display result in a new column with MySQL
- MySQL query to count occurrences of distinct values and display the result in a new column?
- MySQL query to get the length of all columns and display the result in a single new column?
- Multiply values of two columns and display it a new column in MySQL?
- How to round MySQL column with float values and display the result in a new column?
- MySQL query to count the duplicate ID values and display the result in a separate column
- MySQL query to sum the Product Price values from similar columns for same customers and display the result in the same column
- Select distinct names from two columns in MySQL and display the result in a single column
- Setting column values as column names in the MySQL query result?
- MySQL query to display the column and its values using OR in WHERE statement
- MySQL query to get the count of values and display the count in a new column ordered in descending order\n
- MySQL query to group by names and display the count in a new column
- MySQL query to multiply values of two rows and add the result
- MySQL query to count the number of 0s and 1s from a table column and display them in two columns?
- MySQL query to count all the column values from two columns and exclude NULL values in the total count?

Advertisements