Sql Query for increase item value price for multiple item(用于增加多个项目的项目价值价格的 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 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于增加多个项目的项目价值价格的 Sql 查询
基础教程推荐
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- oracle区分大小写的原因? 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在多列上分布任意行 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
