MySQL查询增加单个查询中多个物料的物料价格?
要在单个查询中增加多个项目的项目值,可以在MySQL中使用CASE语句。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> ProductName varchar(20), -> ProductPrice int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Product-1',700);
mysql> insert into DemoTable values('Product-2',1000);
mysql> insert into DemoTable values('Product-3',3000);使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------------+--------------+ | ProductName | ProductPrice | +-------------+--------------+ | Product-1 | 700 | | Product-2 | 1000 | | Product-3 | 3000 | +-------------+--------------+ 3 rows in set (0.00 sec)
这是MySQL查询,用于增加多个商品的商品价格-
mysql> update DemoTable -> set ProductPrice= -> case when ProductName='Product-1' then ProductPrice+((ProductPrice*20)/100) -> when ProductName='Product-2' then ProductPrice+((ProductPrice*40)/100) -> when ProductName='Product-3' then ProductPrice+((ProductPrice*60)/100) -> end; Rows matched: 3 Changed: 3 Warnings: 0
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------------+--------------+ | ProductName | ProductPrice | +-------------+--------------+ | Product-1 | 840 | | Product-2 | 1400 | | Product-3 | 4800 | +-------------+--------------+ 3 rows in set (0.00 sec)
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬