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> 

  进行判断。

posted @ 2018-11-18 20:24  创可贴Y  阅读(9835)  评论(1编辑  收藏  举报