MySql---case when的各种用法
程序员文章站
2022-09-05 15:10:35
话不多说,直接贴sql。SELECTDATA_VALUE dataValue,NUMBER number,PARAM param,CASEWHEN NUMBER = #{item.number} AND PARAM = LEFT(#{item.param}, 4) THEN #{item.ratedVolt}
话不多说,直接贴sql。
一、入参是列表,出参要返回入参中对应的数据
SELECT
DATA_VALUE dataValue,
NUMBER number,
PARAM param,
CASE
<foreach collection="mapList" item="item" open="" close="" separator=",">
WHEN NUMBER = #{item.number} AND PARAM = LEFT(#{item.param}, 4) THEN #{item.vo}
</foreach>
ELSE '0'
END vo,
CASE
<foreach collection="mapList" item="item" open="" close="" separator=",">
WHEN NUMBER = #{item.number} AND PARAM = LEFT(#{item.param}, 4) THEN #{item.id}
</foreach>
ELSE '0'
END id
FROM
${tableName}
WHERE
PARAM IN
<foreach collection="mapList" item="item" open="(" close=")" separator=",">
LEFT(#{item.param}, 4)
</foreach>
AND NUMBER IN
<foreach collection="mapList" item="item" open="(" close=")" separator=",">
#{item.number}
</foreach>
本文地址:https://blog.csdn.net/qq_36897177/article/details/108998180
上一篇: 《MSSQL2008进阶教程》之一“SQL分组查询”
下一篇: Oracle 多表查询