首页 文章资讯内容详情

使用SQL查询从MySQL字段中的存储价格中扣除20%?

2026-06-04 1 花语

假设存储的价格包含20%的营业税。现在,让我们首先创建一个表-

create table DemoTable ( Price int );

使用插入命令在表中插入一些记录-

insert into DemoTable values(20); insert into DemoTable values(40); insert into DemoTable values(80); insert into DemoTable values(60);

使用select语句显示表中的所有记录-

select *from DemoTable;

这将产生以下输出-

+-------+ | Price | +-------+ | 20 | | 40 | | 80 | | 60 | +-------+ 4 rows in set (0.00 sec)

以下是从存储价格中删除20%的查询。因此,因为我们也有20%的营业税,所以120/100=1.2-

update DemoTable set Price=Price/1.2; Rows matched: 4 Changed: 4 Warnings: 0

让我们再次检查表记录-

select *from DemoTable;

这将产生以下输出-

+-------+ | Price | +-------+ | 17 | | 33 | | 67 | | 50 | +-------+ 4 rows in set (0.00 sec)