qq_41908367 2022-02-10 15:03 采纳率: 90.4%
浏览 56
已结题

请问mysql用mybatis循环执行3万条数据有什么办法快一点


<foreach collection="list" item="item" index="index" open="" close="" separator=";">
        update total_score set score=#{item.score}
        where user_id =(select id from sys_admin where uk_account=#{item.username})
        and time=#{item.time}
        </foreach>

像这样执行要40多秒,怎么能快一些呢?

  • 写回答

3条回答 默认 最新

  • liuyh1024 2022-02-10 16:52
    关注

    你参照这个写法试试

    复制代码
    <update id="batchUpdate" parameterType="list">
             update songs
                <trim prefix="set" suffixOverrides=",">
                     <trim prefix="path =case" suffix="end,">
                         <foreach collection="list" item="i" index="index">
                                 <if test="i.songid!=null">
                                      when songid=#{i.songid} then #{i.path}
                                 </if>
                         </foreach>
                      </trim>
                 </trim>
                where songid in 
                <foreach collection="list"  item="i" index="index" open="(" separator="," close=")">
                  #{i.songid}
              </foreach>
        </update>
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 2月23日
  • 已采纳回答 2月15日
  • 创建了问题 2月10日