- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to subtract the same amount from all values in a column with MySQL?
Let us first create a table −
mysql> create table DemoTable741 (Number int); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable741 values(70); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable741 values(55); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable741 values(89); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable741 values(79); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable741 values(34); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable741;
This will produce the following output -
+--------+ | Number | +--------+ | 70 | | 55 | | 89 | | 79 | | 34 | +--------+ 5 rows in set (0.00 sec)
Following is the query to subtract the same amount from all the values in a column −
mysql> select (Number-20) AS Result from DemoTable741;
This will produce the following output -
+--------+ | Result | +--------+ | 50 | | 35 | | 69 | | 59 | | 14 | +--------+ 5 rows in set (0.00 sec)
- Related Articles
- How to subtract seconds from all the date records in a MySQL column?
- Getting maximum from a column value and set it for all other values in the same column with MySQL?
- MySQL query to calculate the total amount from column values with Cost and Quantity?
- How to update a column with the same values (not all) using UPDATE, SET and LIMIT in MySQL?
- How to display two different sums of the same price from column Amount in MySQL?
- Concatenate two values from the same column with different conditions in MySQL
- How to subtract column values from column means in R data frame?
- How to select different values from same column and display them in different columns with MySQL?
- R programming to subtract all values in a vector from all values in another vector.
- Get the sum of last 3 digits from all the values in a column with MySQL
- How to set all values in a single column MySQL Query?
- How to concatenate all values of a single column in MySQL?
- How to return rows that have the same column values in MySQL?
- How to strip all spaces from a column in MySQL?
- Get all the records with two different values in another column with MySQL

Advertisements