我有一个文件包含一些浮动数字。它们是由python的时间()函数产生的。这是我想要存储在字段中的值的一个例子,
0.0034867459908127785我要把号码存起来。然后,我想查询列的MAX。当我将值存储在FLOAT()类型的列中时,它被舍入为:0.00348675。然后,当我询问MAX时,我得到:0.0034867459908127785,这在我的情况下是不可接受的。我不想改变数字。
我怎样才能把这些大浮子按原样储存呢?然后查询MAX并得到存储的确切数字?我不希望MYSQL绕过任何东西。我需要完整的数字。
发布于 2018-09-29 12:04:58
**First Approch:**您可以将数据保存为十进制,并以下列方式获取最大值:
CREATE TABLE `save_processtime1` (
`id` INT(11) NOT NULL,
`point_decimal` DECIMAL(25,20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;
INSERT INTO `save_processtime1` (`id`, `point_decimal`) VALUES('1','0.0034867459008127785');
INSERT INTO `save_processtime1` (`id`, `point_decimal`) VALUES('2','0.0034867459908127785');
INSERT INTO `save_processtime1` (`id`, `point_decimal`) VALUES('3','0.0034867459908127001');
INSERT INTO `save_processtime1` (`id`, `point_decimal`) VALUES('4','0.1000000021200021011');
INSERT INTO `save_processtime1` (`id`, `point_decimal`) VALUES('5','0.0032867459908127785');
mysql>SELECT MAX(point_decimal) FROM save_processtime;
+-----------------------+
| MAX(point_decimal) |
+-----------------------+
| 0.1000000021200021011 |
+-----------------------+其他方法:
您可以将这些数据保存到带有字段的表中,作为VARCHAR。只需得到最大的能量场。
虚拟表结构:
CREATE TABLE `save_processtime` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`point_num` varchar(30) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
insert into `save_processtime` (`id`, `point_num`) values('1','0.0034867459008127785');
insert into `save_processtime` (`id`, `point_num`) values('2','0.0034867459908127785');
insert into `save_processtime` (`id`, `point_num`) values('3','0.0034867459908127001');
insert into `save_processtime` (`id`, `point_num`) values('4','0.1000000021200021011');
insert into `save_processtime` (`id`, `point_num`) values('5','0.0032867459908127785');最大时间的输出:
mysql> SELECT MAX(point_num) FROM save_processtime;
+-----------------------+
| MAX(point_num) |
+-----------------------+
| 0.1000000021200021011 |
+-----------------------+希望这是你想要的!第一种方法比第二种方法更好:)
https://stackoverflow.com/questions/52567593
复制相似问题