本文介绍了用于增加多个项目的项目价值价格的 Sql 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写 Sql Query 以按百分比增加商品价格.
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 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!