本文共 1317 字,大约阅读时间需要 4 分钟。
之所以记录一下这篇博文,是因为前段时间搞的一个查询发现要从00:00:00这个时间段开始,必须要通过拼接字符串。
SELECT T.*, U.USER_SINGLE_FEE FROM TAB_TAG_LEASE_APPLY T LEFT JOIN TAB_TAG_LEASE_USER U ON T.APPLY_USER_ID = U.USER_ID WHERE T.IS_DELETE = 0 AND T.APPLY_USER_ID = #{userId,jdbcType=INTEGER} AND T.APPLY_STATUS=#{applyStatus,jdbcType=INTEGER} <--3天内的记录--> AND T.CREATE_TIME =]]> TO_DATE(TO_CHAR(SYSDATE-3,'yyyy/mm/dd')||' 00:00:00','yyyy/mm/dd hh24:mi:ss') AND T.CREATE_TIME TO_DATE(#{listTime},'yyyy/mm/dd hh24:mi:ss') <--7天内的记录--> AND T.CREATE_TIME =]]> TO_DATE(TO_CHAR(SYSDATE-7,'yyyy/mm/dd')||' 00:00:00','yyyy/mm/dd hh24:mi:ss') AND T.CREATE_TIME TO_DATE(#{listTime},'yyyy/mm/dd hh24:mi:ss') <--30天内的记录--> AND T.CREATE_TIME =]]> TO_DATE(TO_CHAR(SYSDATE-30,'yyyy/mm/dd')||' 00:00:00','yyyy/mm/dd hh24:mi:ss') AND T.CREATE_TIME TO_DATE(#{listTime},'yyyy/mm/dd hh24:mi:ss') <--半年内的记录--> AND T.CREATE_TIME =]]> TO_DATE(TO_CHAR(TRUNC(ADD_MONTHS(SYSDATE, -6)),'yyyy/mm/dd')||' 00:00:00','yyyy/mm/dd hh24:mi:ss') AND T.CREATE_TIME TO_DATE(#{listTime},'yyyy/mm/dd hh24:mi:ss') <--当前年的记录--> AND TO_CHAR(T.CREATE_TIME, 'yyyy') = TO_CHAR(SYSDATE, 'yyyy') ORDER BY T.CREATE_TIME DESC
转载于:https://www.cnblogs.com/geekdc/p/8594929.html