首页 > 数据库技术 > 详细

MySQL DataType--当整数列遇到小数

时间:2019-06-12 16:49:11      阅读:199      评论:0      收藏:0      [点我收藏+]

初始化数据:

## 创建测试表
CREATE TABLE `tb002` (
  `c1` int(11) NOT NULL AUTO_INCREMENT,
  `c2` int(11) DEFAULT NULL,
  `c3` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`c1`),
  KEY `IDX_C2` (`c2`)
);

## 插入测试数据
insert into tb002(c2,c3) select 1428,1428;
insert into tb002(c2,c3) select 1429,1429;
insert into tb002(c2,c3) select 1430,1430;

查看当前表中数据:

## 查看表中数据
SELECT * FROM tb002;

+----+------+------+
| c1 | c2   | c3   |
+----+------+------+
|  1 | 1428 | 1428 |
|  2 | 1429 | 1429 |
|  3 | 1430 | 1430 |
+----+------+------+

测试1:

## 测试1
select * from tb002 where c2=1429.5;
+----+------+------+
| c1 | c2   | c3   |
+----+------+------+
|  3 | 1430 | 1430 |
+----+------+------+


## 测试2
select * from tb002 where c2<1429.5;
+----+------+------+
| c1 | c2   | c3   |
+----+------+------+
|  1 | 1428 | 1428 |
|  2 | 1429 | 1429 |
+----+------+------+


## 测试3
select * from tb002 where c2<=1429.5;
+----+------+------+
| c1 | c2   | c3   |
+----+------+------+
|  1 | 1428 | 1428 |
|  2 | 1429 | 1429 |
+----+------+------+


## 测试4:
select * from tb002 where c2=1429.5 or c2<1429.5;
+----+------+------+
| c1 | c2   | c3   |
+----+------+------+
|  1 | 1428 | 1428 |
|  2 | 1429 | 1429 |
+----+------+------+


## 测试5:
select * from tb002 where c2=1429.5 union select * from tb002 where c2<1429.5;
+----+------+------+
| c1 | c2   | c3   |
+----+------+------+
|  3 | 1430 | 1430 |
|  1 | 1428 | 1428 |
|  2 | 1429 | 1429 |
+----+------+------+

上面测试中发现:

1、where c2=1429.5 or c2<1429.5 与 where c2<=1429.5 和 where c2=1429.5查询结果相同

2、where c2<=1429.5的查询结果中不包含where c2=1429.5的查询结果

 

测试2:

## 查询1
select * from tb002 force index(IDX_C2) where c2=1429.5;
+----+------+------+
| c1 | c2   | c3   |
+----+------+------+
|  3 | 1430 | 1430 |
+----+------+------+


## 查询2
select * from tb002 force index(primary) where c2=1429.5;
Empty set (0.00 sec)

上面测试中发现:

1、强制走不同索引会导致查询结果不同(两次查询过程中无任何数据变化,使用RR事务隔离级别)

 

MySQL DataType--当整数列遇到小数

原文:https://www.cnblogs.com/gaogao67/p/11010412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!