snippetsqlMinor
how to increase column values by 20 percent using mysql
Viewed 0 times
columnpercentmysqlincreaseusinghowvalues
Problem
How do i increase the values in a column with percentage increment using MySQL, for example:
How do i increase the values in price column by 20% using one sql query (MySQL)?
ID price
1 500
2 800
3 450How do i increase the values in price column by 20% using one sql query (MySQL)?
Solution
Simply calculate 20% of actual price:
or a shorter way:
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.