mysql中between...and..的使用,及時間范圍的查詢


博主原創,轉載注明出處:

      在mysql應用中,以范圍進行查詢的很多是以時間范圍作為條件進行范圍查詢的,時間范圍查詢有

很多種寫法,首先總結一下between....and...的使用方法:

<select id="conCurrentCount" parameterType="map" resultType="int">
        SELECT COUNT(*) FROM tbl_report_info
        <where>
            ActionTime BETWEEN #{startTime} AND #{endTime}
        </where>
    </select>

講解:

SELECT * FROM tbl_student_info WHERE `height` between 1113 and 1122     

等同於:
SELECT
* FROM tbl_student_info WHERE `height` >= 1113 and `height` <= 1122
    SELECT * FROM tbl_student_info WHERE `createDate` between '20170101020304' and '20180101020304'    
        等同於:
    SELECT * FROM tbl_student_info WHERE `createDate` >= '20170101020304' and `createDate` <= '20180101020304'    

另外一種時間范圍查詢的方法如下:分別設定開始時間和結束時間:

<if test="endTime!=null and !&quot;&quot;.equals(endTime.trim())">
            AND m.endTime &lt; #{endTime}
        </if>
           <if test="startTime!=null  and !&quot;&quot;.equals(startTime.trim())">
            AND m.startTime &gt; #{startTime}
        </if>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM