MySQL 插入一张表的部分数据到另一张表

  1. # 导入账户数据 - 总店id需要手动补全
  2. insert into pro_user_account (id, store_id, branch_id, user_name, password, real_name,
  3. status, create_user, update_user,
  4. create_time, update_time)
  5. SELECT user_id,
  6. '0',
  7. IFNULL(sup_user_id,'0'),
  8. user_name,
  9. passwd,
  10. real_name,
  11. status,
  12. null,
  13. null,
  14. create_time,
  15. update_time
  16. from pro_user_info as a
  17. where status = 0
  18. and passwd is not null;
  1. `Mybatis` 数组查询
  2. ```xml
  3. <foreach collection="list" item="employeeId" index="index" open="(" close=")" separator=",">
  4. #{employeeId}
  5. </foreach>
  6. <foreach collection="array" item="employeeId" index="index"
  7. open="(" close=")" separator=",">
  8. #{employeeId}
  9. </foreach>
  10. 根据数组批量查询
  11. List<Privilege> selectPrivilegeByIds(@Param("privilegeIds") Integer[] privilegeIds);
  12. <select id="selectPrivilegeByIds" resultMap="BaseResultMap" >
  13. select
  14. <include refid="Base_Column_List" />
  15. from diary_privilege
  16. where id in
  17. <foreach collection="array" item="item" index="index" open="(" separator="," close=")">
  18. #{item}
  19. </foreach>
  20. </select>
  21. 根据集合插入批量插入
  22. int insertEmployeeRole(EmployeeRoleVo employeeRole);(EmployeeRoleVo中包含List<Role> roleList)
  23. <insert id="insertEmployeeRole" parameterType="com.jimmy.demo.vo.EmployeeRoleVo" >
  24. insert into diary_employee_role (employeeId,roleId)
  25. values
  26. <foreach collection="roleList" item="item" index="index" separator="," >
  27. (#{employee.eid},#{item.id})
  28. </foreach>
  29. </insert>
  1. <a name="3ymrdx"></a>
  2. ### 根据List<Object> 批量删除
  3. ```sql
  4. <delete id="deleteBatchByCondition">
  5. delete from BOM_PART_PARTS_P A
  6. where exists
  7. (
  8. select 1 from(
  9. <foreach collection="list" item="item" index="index" separator="union all">
  10. select B.PART_PARTS_CODE from BOM_PART_PARTS_P B where 1=1
  11. and B.PART_CODE = #{item.partCode,jdbcType=VARCHAR}
  12. and B.PARENT_PART_CODE = #{item.parentPartCode,jdbcType=VARCHAR}
  13. and B.LINE_NO = #{item.lineNo,jdbcType=VARCHAR}
  14. and B.ACTIVATE = 0
  15. </foreach>
  16. )S where A.PART_PARTS_CODE = S.PART_PARTS_CODE
  17. )
  18. </delete>