对于入参是list 或者arrays的情况需要将入参作为过滤条件在mysql的配置中,可以参考:https://blog.youkuaiyun.com/chenaini119/article/details/51699619
demo:这个样例是入参中有一个business的数组,另外,limit 后面只能带常量,不能是表达式,所以只有在请求过来的时候组装入参。
<select id="getBusiness" parameterType="***RequestConditionBean" resultMap="TblstatReport">
select product,business,action,date_format(status_date,'%Y%m%d%H') listdate,format(AVG(fail_time_average),2) fail_time_average,format(AVG(suss_time_average),2) suss_time_average,SUM(fail_count) fail_count,SUM(succ_count) succ_count,SUM(users) usercount,SUM(realusers) realusers,SUM(count) count from stat_report
where stat_type=#{statType} and product=#{product}
<if test="business != null" >
and business in
<foreach collection="business" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="action != null" >
and action = #{action,jdbcType=VARCHAR}
</if>
<if test="predays != null" >
and DATE_SUB(CURDATE(), INTERVAL #{predays} DAY) <= date(status_date)
</if>
group by business,listdate
ORDER BY
listdate DESC,succ_count DESC limit 0,#{startNum}
</select>
2、 group by
select cat_id ,title,count(*) as count1 from tbl_supply_item GROUP BY cat_id ORDER BY count1 DESC
我是想统计cat_id 相同的情况下每种catid有多少个,同时希望看到对应的catid,上面是可以的,但是title就显示不全了,明显的只会显示第一条的title,想想也明白,cat_id被groupby了那么就会将所有的catid算成一条,然而title每个catid是有很多个,显然是不可能显示完全的,想法就自我矛盾了。由于catid被groupby了所有相同的显示一条,那么catid也是同一个值,所以显示上直接显示是可以的。
3、大于等于 符号
第一种写法(1):原符号 < <= > >= & ' "
替换符号 < <= > >= & ' "
例如:sql如下:createTime >= #{startTime} and createTime <= #{endTime}
第二种写法(2):大于等于<![CDATA[ >= ]]> 小于等于<![CDATA[ <= ]]>
例如:sql如下:createTime <![CDATA[ >= ]]> #{startTime} and createTime <![CDATA[ <= ]]> #{endTime}