mybatis 关于时间比较的sql

mysql、oracle关于时间格式化的函数:

Mysql中使用DATE_FORMAT函数: DATE_FORMAT(create_date,'%Y-%m-%d  %H:%i:%S')

Oracle中使用to_date函数和to_char函数: TO_DATE('2018-11-24 14:01:39','yyyy-MM-dd hh24:mi:ss')

                                                                 或TO_CHAR(DATE,'yyyy-MM-dd hh24:mi:ss')

以下为mysql例子:

时间7天之内:

  DATE_FORMAT(CURDATE(), '%Y-%m-%d')-interval 7 day

  DATE_SUB(CURDATE(), INTERVAL 7 DAY)

<select id="pageAppNodeManage" resultMap="BaseResultMap" parameterType="Map" >
    select  *   from progress_node_manage
    where  circuit_id =  #{manageParam.circuitId,jdbcType=VARCHAR}
    and  progress_grade = #{manageParam.progressGrade,jdbcType=CHAR}
    and  del_flag = '0'
    <if test="manageParam.projectId != null and manageParam.projectId != ''">
      and  project_id =  #{manageParam.projectId,jdbcType=VARCHAR}
    </if>
    <if test="manageParam.workAreaId != null and manageParam.workAreaId != ''">
      and  work_area_id =  #{manageParam.workAreaId,jdbcType=VARCHAR}
    </if>
    <if test="manageParam.reportPersonId != null and manageParam.reportPersonId != ''">
      and  report_person_id =  #{manageParam.reportPersonId,jdbcType=VARCHAR}
    </if>
    <if test="manageParam.status != null and manageParam.status == '0'.toString()">
      <![CDATA[AND (DATE_FORMAT(plan_end_time, '%Y-%m-%d') < DATE_FORMAT(CURDATE(), '%Y-%m-%d'))]]>
      AND real_end_time is null
    </if>
    <if test="manageParam.status == '1'.toString()">
      AND CURDATE() BETWEEN (DATE_FORMAT(plan_end_time, '%Y-%m-%d')-interval 7 day) and DATE_FORMAT(plan_end_time, '%Y-%m-%d')
      AND real_end_time is null
    </if>
    <if test="manageParam.status == '2'.toString()">
      <![CDATA[AND (DATE_FORMAT(real_end_time, '%Y-%m-%d') > DATE_FORMAT(plan_end_time,'%Y-%m-%d'))]]>
    </if>
    <if test="manageParam.status == '3'.toString()">
      <![CDATA[AND (DATE_FORMAT(real_end_time, '%Y-%m-%d') < DATE_FORMAT(plan_end_time,'%Y-%m-%d'))]]>
    </if>
    <if test="manageParam.status == '4'.toString()">
      and plan_start_time is not null and  real_end_time is  null and real_start_time is  null
    </if>
    <if test="manageParam.status == '5'.toString()">
      and real_start_time is not null
      and  real_end_time is null and  plan_start_time is not null
    </if>
    <if test="manageParam.status == '6'.toString()">
      and real_end_time is null
    </if>
    <if test="manageParam.status == '7'.toString()">
      and real_end_time is not null
    </if>
    order by plan_end_time asc
  </select>

 

相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页