Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Query for increase item value price for multiple item

I want to write Sql Query for increase item price by percentage.

Scenario is :-

In table, I have 3 coloumn : ID, Item-Name, Price

Example : If item-Name is T-shirt, Increase price by 10%

         item-Name is Jins , Increase price by 50%

         item-Name is top , Increase price by 5%
like image 985
Anurag Jain Avatar asked Dec 03 '25 14:12

Anurag Jain


1 Answers

If you are looking to update the table you can do conditional update.

update table_name
set 
price = 
case 
 when `Item-Name` = 'T-shirt' then price+( (price*10) /100 )
 when `Item-Name` = 'Jins' then price+( (price*50) /100 )
 when `Item-Name` = 'top' then price+( (price*5) /100 )
end ;

And if you are looking to show the increased price without doing any update in the table at the time of select then you can do as below.

select id,`Item-Name`,price,
case 
     when `Item-Name` = 'T-shirt' then price+( (price*10) /100 )
     when `Item-Name` = 'Jins' then price+( (price*50) /100 )
     when `Item-Name` = 'top' then price+( (price*5) /100 )
     else price
    end as new_price from table_name;
like image 134
Abhik Chakraborty Avatar answered Dec 05 '25 04:12

Abhik Chakraborty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!