代码改变世界

时间范围查询的sql代码

2017-07-28 09:42  Lose丶word  阅读(1645)  评论(0编辑  收藏  举报

mysql:

<if test="startTime != null">
  <![CDATA[and date_format(time,'%Y-%m-%d')>=date_format(#{startTime},'%Y-%m-%d')]]>
</if>
<if test="endTime != null">
  <![CDATA[and date_format(time,'%Y-%m-%d')<=date_format(#{endTime},'%Y-%m-%d')]]>
</if>

 

oracle:

<if test="logTimeStart != null and logTimeStart != ''">
    convert(char(10),LogTime,120) >= convert(char(10),#{logTimeStart},120)
</if>
<if test="logTimeEnd != null and logTimeEnd != ''">
   convert(char(10),LogTime,120) &lt;= convert(char(10),#{logTimeEnd},120)
</if>

 

sql server:

<if test="startTm != null and startTm != ''">
  <![CDATA[AND TO_CHAR(time,'yyyy-mm-dd') >= TO_CHAR(#{startTm,jdbcType=TIMESTAMP},'yyyy-mm-dd')]]>
</if>
<if test="endTm != null and endTm != ''">
  <![CDATA[AND TO_CHAR(time,'yyyy-mm-dd') <= TO_CHAR(#{endTm,jdbcType=TIMESTAMP},'yyyy-mm-dd')]]>
</if>