HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

how to increase column values by 20 percent using mysql

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
columnpercentmysqlincreaseusinghowvalues

Problem

How do i increase the values in a column with percentage increment using MySQL, for example:

ID      price
1       500
2       800
3       450


How do i increase the values in price column by 20% using one sql query (MySQL)?

Solution

Simply calculate 20% of actual price:

update your_table
set price = price + (price * 20.0 / 100.0)
where id = (some condition)


or a shorter way:

update your_table
set price = price * 1.2
where id = (some condition)

Code Snippets

update your_table
set price = price + (price * 20.0 / 100.0)
where id = (some condition)
update your_table
set price = price * 1.2
where id = (some condition)

Context

StackExchange Database Administrators Q#141698, answer score: 8

Revisions (0)

No revisions yet.