MySql中case...when...的用法

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

and abc.属性1 in

#{item}

AND abc.属性2 in

#{item}

AND abc.属性3 in

#{item}

©著作权归作者所有:来自51CTO博客作者zjy666的原创作品,如需转载,请注明出处,否则将追究法律责任

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐