Usage of case...when... in MySql

<select id="getXxx" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
(CASE WHEN ( xyz.字段1 IS NULL ) THEN '未监控'
WHEN ( xyz.字段1 is not null and (xyz.字段2 = 0 or xyz.字段2 is null) ) THEN '0'
WHEN ( xyz.字段1 is not null and xyz.字段2 > 0 AND xyz.字段2 <= 0.15 ) THEN '0%-15%'
...
...
WHEN ( xyz.字段1 is not null and xyz.字段2 > 0.6 AND xyz.字段2 <= 0.85 ) THEN '60%-85%'
ELSE '85%-100%' END ) AS xxx
FROM
a_b_c abc
LEFT JOIN x_y_z xyz ON abc.id = xyz.id
<where>
<if test="list1 != null and list1.size>0">
and abc.属性1 in
<foreach collection ="list1" item="item" index= "index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="list2 != null and list2.size>0">
AND abc.属性2 in
<foreach collection ="list2" item="item" index= "index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="list3 != null and list3.size>0">
AND abc.属性3 in
<foreach collection ="list3" item="item" index= "index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
</select>

Guess you like

Origin blog.51cto.com/14666686/2562493