MySql—case when的各种用法

话不多说,直接贴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

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐