MySQL max 和 MIN 函数显示 100 及以上为最小值

MySQL max and MIN function showing 100 and above as minimum value

我进行了查询以显示数据库中的最大值和最小值,但效果不佳。在我们有 100 及以上的值 returns 的情况下,它最低而不是 99 及以下

SELECT MIN(total) AS min, MAX(total) AS max  FROM `results` WHERE `term_id` = 2 AND  `class_id` = 8 AND `subject_id` = 152

结果

min     max     
100     96

这是我的 table 结构:

CREATE TABLE `results` (
  `rst_id` bigint(20) NOT NULL,
  `user_id` int(11) NOT NULL,
  `subject_id` int(11) NOT NULL,
  `first_test` varchar(2) DEFAULT NULL,
  `second_test` varchar(2) DEFAULT NULL,
  `exam` varchar(2) DEFAULT NULL,
  `total` varchar(3) NOT NULL,
  `position` int(11) DEFAULT NULL,
  `term_id` int(11) NOT NULL,
  `session_id` int(11) NOT NULL,
  `class_id` int(11) NOT NULL,
  `is_new` tinyint(1) DEFAULT '1',
  `is_upd` tinyint(1) NOT NULL DEFAULT '0',
  `date_declared` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `date_updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `declared_by` int(11) NOT NULL,
  `updated_by` int(11) DEFAULT NULL,
  `deleted` tinyint(1) DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

我以为你有一个 varchar 并且是按字典顺序排序的

使用

SELECT MIN(total + 0) AS min, MAX(total + 0) AS max  
FROM `results` 
WHERE `term_id` = 2 AND  `class_id` = 8 AND `subject_id` = 152

这会将其转换为数字