0
点赞
收藏
分享

微信扫一扫

chatgpt赋能python:Python中的UTF-8

青鸾惊鸿 2023-06-09 阅读 51

省流:

日,捞2023年1月1日,create_time>='2023-01-01' and create_time<'2023-01-02'

月,捞2023年1月,create_time>='2023-01-01' and create_time<'2023-02-01'

 

详解:

在某个区间内,一般使用大于等于和小于。

例如捞出表中2023年6月9日的数据。

select * from t1 where create_time>='2023-06-09' and create_time<'2023-06-10'

这里日期其实有隐式的时间在里面,即,2023-06-092023-06-09 00:00:00

这段sql等价于:

select * from t1 where create_time>='2023-06-09 00:00:00' and create_time<'2023-06-10 00:00:00'

捞出某个月的数据也一样

不再需要使用date_format(create_time,'%Y-%m'),因为函数会对每行数据的create_time进行处理,这样会影响性能。

只需要这样写,例如捞出6月的数据:

select * from t1 where create_time>='2023-06-01' and create_time<'2023-07-01'

mybatis中写法

在mybatis中,一般会传参,使用变量:

select * from t1 where create_time>=#{startTime} and create_time<#{endTime}

由于xml文件中小于号需要转义,所以我们这样写:

select * from t1 where create_time>=#{startTime} and #{endTime}>create_time
举报

相关推荐

0 条评论