mysql 8.0 cte查询以及批量操作

1.批量插入

<insert id="batchInsert" parameterType="java.util.List">
INSERT INTO
sal_basic_scope (id, property_id, sub_id,
user_tableinfo, description, is_delete)
values
<foreach item="item" index="index" collection="list" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.propertyId,jdbcType=VARCHAR}, #{item.subId,jdbcType=VARCHAR},
#{item.userTableinfo,jdbcType=VARCHAR}, #{item.description,jdbcType=VARCHAR}, #{item.isDelete,jdbcType=VARCHAR}
)
</foreach>
</insert>

2.批量更新

<!--   批量更新数据 -->
<update id="batchUpdate" parameterType="java.util.List">
update STA_RECEPTION_MEMBER
<trim prefix="set" suffixOverrides=",">
 <trim prefix="OFFICE_ID =case" suffix="end,">  
     <foreach collection="list" item="cus">  
         <if test="cus.officeId!=null">  
             when RECEPTION_ID=#{cus.receptionId} then #{cus.officeId}  
         </if>  
     </foreach>  
 </trim>
  
 
</trim>  
<where>  
    <foreach collection="list" separator="or" item="cus">  
        RECEPTION_ID = #{cus.receptionId}  
    </foreach>  
</where>  

</update>

3.批量删除

<delete id="batchDelete" parameterType="java.util.List">
delete from t_kq_shift_month
where id in
<foreach collection="list" item="item"  open="(" close=")" separator=",">
#{item.id}
</foreach>
</delete>

4.cte根据某个条件联合查询(自关联查询)

WITH RECURSIVE test(id, title, type,parent_id)
                     AS
                     (

                       SELECT DISTINCT id, title,type,parent_id
                       FROM limis_template WHERE title like  CONCAT('%', #{title}, '%') and  type =#{type} and deleted=0
                       UNION ALL
                       SELECT e.id, e.title,e.type,e.parent_id
                       FROM test AS ep JOIN limis_template AS e  ON ep.parent_id = e.id
                     )SELECT * FROM test;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值