- 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
Remove 20% from stored price in MySQL field, using SQL query?
Let’s say the stored price is inclusive of 20% sales tax. Now, let us first create a table −
mysql> create table DemoTable ( Price int ); Query OK, 0 rows affected (1.09 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(80); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Price | +-------+ | 20 | | 40 | | 80 | | 60 | +-------+ 4 rows in set (0.00 sec)
Following is the query to remove 20% from the stored price. Therefore, 120/100= 1.2 since we have 20% sales tax as well −
mysql> update DemoTable set Price=Price/1.2; Query OK, 4 rows affected (0.11 sec) Rows matched: 4 Changed: 4 Warnings: 0
Let us check table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Price | +-------+ | 17 | | 33 | | 67 | | 50 | +-------+ 4 rows in set (0.00 sec)
- Related Articles
- Implement Dynamic SQL query inside a MySQL stored procedure?
- Why I am facing a problem using the field 'from' in SQL query?
- Remove seconds from time field in MySQL?
- How to remove -XXX from Zip Code field using MySQL REGEXP?
- Remove decimal from records and sum them using a MySQL query
- MySQL query to count comma’s from field value?
- MySQL Sum Query with IF Condition using Stored Procedure
- MySQL query to extract last word from a field?
- MySQL query to extract first word from a field?
- Get database name from a query implemented in a MySQL Stored Procedure?
- Implement DELETE query in MySQL stored procedure
- How to remove special characters from a database field in MySQL?
- MySQL query to remove special characters from column values?
- Implement Conditional MySQL Query in a stored procedure?
- MySQL query to return 5 random records from last 20 records?

Advertisements