使用 SQL 查询从 MySQL 字段中存储的价格中删除 20%?
mysqlmysqli database更新于 2025/12/10 3:24:17
假设存储的价格包含 20% 的销售税。现在,让我们首先创建一个表 −
mysql> create table DemoTable ( Price int ); Query OK, 0 rows affected (1.09 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(80); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.18 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
这将产生以下输出 −
+-------+ | Price | +-------+ | 20 | | 40 | | 80 | | 60 | +-------+ 4 rows in set (0.00 sec)
以下查询从存储的价格中减去 20%。因此,120/100= 1.2,因为我们还有 20% 的销售税 −
mysql> update DemoTable set Price=Price/1.2; Query OK, 4 rows affected (0.11 sec) Rows matched: 4 Changed: 4 Warnings: 0
让我们再次检查表记录 −
mysql> select *from DemoTable;
这将产生以下输出 −
+-------+ | Price | +-------+ | 17 | | 33 | | 67 | | 50 | +-------+ 4 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

