SQL查询多个项目的增加项目价值价格 [英] Sql Query for increase item value price for multiple item
本文介绍了SQL查询多个项目的增加项目价值价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写SQL查询以按百分比增加商品价格.
I want to write Sql Query for increase item price by percentage.
场景是:-
在表中,我有3列文字:ID,商品名称,价格
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%
推荐答案
如果您要更新表,则可以进行条件更新.
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;
这篇关于SQL查询多个项目的增加项目价值价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文