SELECT * FROM user WHERE delete_flag = 0 AND create_time BETWEEN '2024-01-01' AND '2024-01-05'
结果中没有包含五号的数据
经过百度发现是因为create_time字段的格式为datatime,格式中是包含时分秒的1,搜索条件中如果没有时分秒则会左含右不含,因此sql语句应改为:
SELECT * FROM user WHERE delete_flag = 0 AND create_time BETWEEN '2024-01-01 00:00:00' AND '2024-01-05 23:59:59'
当然,也可以使用>= 和 <= 来圈定范围