以下是使用 MacOS 运行的 MySQL(8.0.x) 中的数据:
ysql> desc t_room;
+--------------+-------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------------+------+-----+---------+-------+
| roomNum | varchar(60) | NO | PRI | NULL | |
| roomType | varchar(20) | NO | | NULL | |
| roomDesc | varchar(400) | YES | | NULL | |
| rentPayDay | tinyint unsigned | YES | | NULL | |
| rentFee | smallint unsigned | NO | | NULL | |
| asstMine | varchar(400) | YES | | NULL | |
| asstOwner | varchar(400) | YES | | NULL | |
| owner | varchar(30) | YES | | NULL | |
| signDate | date | YES | | NULL | |
| contract | mediumblob | YES | | NULL | |
| roomFacility | varchar(120) | YES | | NULL | |
+--------------+-------------------+------+-----+---------+-------+
11 rows in set (0.00 sec)
mysql> select rentPayDay from t_room;
+------------+
| rentPayDay |
+------------+
| 15 |
| 20 |
| 25 |
| 10 |
+------------+
4 rows in set (0.00 sec)
当我使用下面的 where 子句进行查询时,一切都很好:
mysql> select roomNum, owner, rentPayDay from t_room where rentPayDay - 10 <= 5;
+---------------+--------+------------+
| roomNum | owner | rentPayDay |
+---------------+--------+------------+
| xxxC-906 | John | 15 |
| xxxxx-908 | Doe | 10 |
+---------------+--------+------------+
2 rows in set (0.00 sec)
但是,当我减去一个可能大于某些rentPayDay 值的值时,如下所示:
mysql> select roomNum, owner, rentPayDay from t_room where rentPayDay - 11 <= 5;
事情出错了:
ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(`dev_learn`.`t_room`.`rentPayDay` - 11)'
有人对此有任何想法吗?为什么 TINYINT 数据不能在 where 子句中减去更大的数值?