欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

相关标签: mysql