mybatis中怎樣使用having?


1.dao層代碼

List<ErgTipSimpleBo> queryListMore(@Param("typeId") Integer typeId,@Param("num") Integer num);

2.mapper.xml

    <select id="queryListMore" resultMap="ergTipTypeMap">
            SELECT MAX(tip_type_id) tip_type_id,`data`,count(data) count from erg_tip
            GROUP BY `data`
            <if test="typeId != null and typeId != 0 " >
                HAVING tip_type_id = #{typeId}
            </if>
            ORDER BY count DESC
            LIMIT #{num}
    </select>

  其實比較簡單,關鍵是添加  

<if test=""></if> 

  進行判斷。


免責聲明!

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



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