mybatis子查询及in在的使用
这是一个字符串循环查询比如接受字符串是张三,李四。location就是张三,李四。
·
这是一个子查询 SELECT a.* from i as a inner join ( select max(datetime) as datetime,asset_name,max(asset_code) as asset_code FROM i <if test="taskId != null and taskId!=''"> WHERE taskid = #{taskId} </if> <if test="type != null and type!=''"> and inout_status = #{type} </if> GROUP BY asset_name ) b on a.asset_code = b.asset_code and a.datetime = b.datetime <if test="inoutStatus != null and inoutStatus!=''"> and inout_status = #{inoutStatus} </if> ORDER BY dateTime DESC
这是一个字符串循环查询比如接受字符串是 张三,李四
<select id="selectIdByLocation" resultType="java.lang.String" >
select dev_id from door_dev_antenna
where door_name in
<foreach item="item" index="index" collection="location.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</select>
location就是 张三,李四

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)