between...and(推荐)
SELECT * FROM tb_code WHERE expired_at BETWEEN '2021-01-01 00:00:00' AND '2021-12-31 23:59:59';
大小于号
SELECT * FROM tb_code WHERE expired_at > '2021-01-01 00:00:00' AND expired_at < '2021-12-31 23:59:59';
转换为比较,create_time若加了索引,不走索引
SELECT * FROM k_student WHERE UNIX_TIMESTAMP(create_time) between UNIX_TIMESTAMP('2019-07-25 00:00:33') and UNIX_TIMESTAMP('2019-07-25 00:54:33')
查询2022年的数据:
select * from day_rate where year(date)='2022'
查询2月份的数据:
select * from day_rate where month(date)='02'
查询2022年2月份的数据:
select * from day_rate where year(date)='2022' and month(date)='02'
查询年初第32天的数据:
select * from day_rate where dayofyear(date)='32'
右端查询报错:
select * from t_ordersetting where orderDate between '2021-09-01' and '2021-09-31';
查询某一天的信息:
SELECT * FROM tb_unload WHERE DATE(created_at)='2023-08-01';
查询今天的记录
SELECT * FROM tb_unload WHERE DATE(created_at)=CURDATE(); SELECT * FROM tb_unload WHERE DATE(created_at)=DATE(NOW());
修改时间 2023-12-18
声明:本站所有文章和图片,如无特殊说明,均为原创发布。商业转载请联系作者获得授权,非商业转载请注明出处。