sql - 如何仅使用 SQL 减去 mySQL 表中的所有价格?

标签 sql mysql

我正在玩下面的东西,但现在还没有。

ALTER TABLE `product_price` CHANGE `price` = `price` - 20;

最佳答案

你要找的是这个:

UPDATE product_price SET price = price - 20;

因此,如果您的数据如下所示:

| id | price         |
|----|---------------|
| 1  | 25.20         |
| 2  | 26.50         |
| 3  | 27.00         |
| 4  | 24.25         |

它会变成这样:

| id | price         |
|----|---------------|
| 1  | 5.20          |
| 2  | 6.50          |
| 3  | 7.00          |
| 4  | 4.25          |

正如 tehvan 在您的评论中指出的那样,ALTER当您想要更改表的结构 时使用。来自文档:

ALTER TABLE enables you to change the structure of an existing table. For example, you can add or delete columns, create or destroy indexes, change the type of existing columns, or rename columns or the table itself. You can also change the comment for the table and type of the table.

如果您想以任何方式更新信息,请使用 UPDATE陈述。

关于sql - 如何仅使用 SQL 减去 mySQL 表中的所有价格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/576809/

相关文章:

PHP PDO 准备查询拒绝正确执行 - 转义问题?

MySQL:使用 mysqldump 转储完整数据库时存储过程、函数和触发器会发生什么

mysql - 从此 MySQL select+join+group 中删除 "Using temporary; Using filesort"

java - 此代码可用于连接到 SQL Server 2008 吗?

mysql - 如果不存在则删除

mysql - 如何替换或更新表中的现有值

mySQL - 输出两个计算字段的总和

mysql - 根据开始日期对事件进行排序

sql - 更新表中的 20 行确实很慢

c# - Sql datareader已经关联高频轮询