首页 > 试题广场 >

MySQL中,查询created_time在2022年之前的

[单选题]
MySQL中,查询created_time在2022年之前的记录,以下查询效率最低的是()?
CREATE TABLE `student_table` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `name` char(10) DEFAULT NULL,
  `created_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `index_created_time` (`created_time`)
) ENGINE=InnoDB

  • SELECT * FROM student_table WHERE created_time < '2022-01-01' ;
  • SELECT * FROM student_table WHERE created_time <= '2021-12-31' ;
  • SELECT * FROM student_table WHERE  substr(created_time,1,10) < '2022';
  • SELECT * FROM student_table WHERE created_time < '2022-01-01 00:00:00' ;
  • SELECT * FROM student_table WHERE created_time < substr('2020-02-11 22:06:17',1,10);
在索引列加函数,索引就失效了,就用不到索引,会扫描全表
发表于 2026-01-04 17:29:10 回复(0)