当前月:
and DATE_FORMAT(a.createTime,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
指定月:
<if test="month!=null and month!=''">
and DATE_FORMAT(a.createTime,'%Y-%m')=#{month}
</if>
两个指定时间间隔:
<if test="startDate!=null and startDate!=''and endDate!=null and endDate!=''">
and a.createTime between #{startDate} and #{endDate}
</if>
本文深入探讨了SQL中针对不同场景的日期筛选技巧,包括当前月份、指定月份及两个指定时间间隔的数据查询方法,通过示例代码展示如何灵活使用DATE_FORMAT函数进行精确的时间筛选。
1万+

被折叠的 条评论
为什么被折叠?



