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> 

  进行判断。

原文地址:https://www.cnblogs.com/liuxiutianxia/p/9979214.html