mapper.xml与sql知识总结

1.已知生日,求年龄

TIMESTAMPDIFF(year,birthday,CURDATE()) age

2.根据字段内有无值,判断状态

ISNULL(die_date)  status

3.mapper.xml里的date类型与mysql中的日期作比较

<if test="null!=start_diagnosed ">and a.diagnosed &gt;= DATE_FORMAT(#{start_diagnosed}, '%Y-%m-%d') </if>
<if test="null!=end_diagnosed ">and a.diagnosed &lt;= DATE_FORMAT(#{end_diagnosed}, '%Y-%m-%d')</if>

注:if判断中date类型不能与空字符串做对比

4.获取时间

now() sysdate()  “yyyy-MM-dd HH-mm-ss”
curdate()“yyyy-MM-dd”
curtime()“HH-mm-ss”
发布了12 篇原创文章 · 获赞 10 · 访问量 342

猜你喜欢

转载自blog.csdn.net/GraySakura/article/details/105183263
今日推荐