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 查询
				
        
 
            
        基础教程推荐
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
 - while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
 - 从字符串 TSQL 中获取数字 2021-01-01
 - 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
 - MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
 - ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
 - 带更新的 sqlite CTE 2022-01-01
 - CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
 - MySQL 5.7参照时间戳生成日期列 2022-01-01
 - 带有WHERE子句的LAG()函数 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				