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