求某一天的数据,但是数据库的格式是datetime 如果你用=是无法求出的,因为数据格式精准到了时分秒,而你用yyyy-MM-dd去匹配的时候是无法等于的。
CREATE TABLE `t4` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`birthday` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
INSERT INTO `avlicy`.`t4`(`id`, `name`, `birthday`) VALUES (1, '小王', '2022-09-20 15:30:08');
INSERT INTO `avlicy`.`t4`(`id`, `name`, `birthday`) VALUES (2, '小绿', '2022-09-21 15:30:19');
INSERT INTO `avlicy`.`t4`(`id`, `name`, `birthday`) VALUES (3, '小瘪', '2022-09-22 15:30:30');
SELECT
*
FROM
t4
WHERE
date_format( birthday, '%Y-%m-%d' )= date_format('2022-09-20 00:00:00','%Y-%m-%d');
select * from t4 where birthday between '2022-09-20' and '2022-09-21';