如何在 MySQL SELECT 中将无符号整数乘以 -1?
mysqlmysqli database更新于 2025/5/21 19:56:17
首先我们创建一个表 −
mysql> create table DemoTable -> ( -> Value int -> ); Query OK, 0 rows affected (0.80 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.14 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
输出
这将产生以下输出 −
+-------+ | Value | +-------+ | 10 | | 20 | | 100 | +-------+ 3 rows in set (0.00 sec)
这是在 SELECT 中将无符号整数乘以 -1 的查询 −
mysql> select cast(Value*-1 as signed) from DemoTable;
输出
这将产生以下输出 −
+--------------------------+ | cast(Value*-1 as signed) | +--------------------------+ | -10 | | -20 | | -100 | +--------------------------+ 3 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

