MySQL 插入一张表的部分数据到另一张表
# 导入账户数据 - 总店id需要手动补全insert into pro_user_account (id, store_id, branch_id, user_name, password, real_name, status, create_user, update_user, create_time, update_time)SELECT user_id, '0', IFNULL(sup_user_id,'0'), user_name, passwd, real_name, status, null, null, create_time, update_timefrom pro_user_info as awhere status = 0 and passwd is not null;
`Mybatis` 数组查询```xml<foreach collection="list" item="employeeId" index="index" open="(" close=")" separator=","> #{employeeId}</foreach><foreach collection="array" item="employeeId" index="index" open="(" close=")" separator=","> #{employeeId}</foreach>根据数组批量查询List<Privilege> selectPrivilegeByIds(@Param("privilegeIds") Integer[] privilegeIds);<select id="selectPrivilegeByIds" resultMap="BaseResultMap" > select <include refid="Base_Column_List" /> from diary_privilege where id in <foreach collection="array" item="item" index="index" open="(" separator="," close=")"> #{item} </foreach></select>根据集合插入批量插入int insertEmployeeRole(EmployeeRoleVo employeeRole);(EmployeeRoleVo中包含List<Role> roleList) <insert id="insertEmployeeRole" parameterType="com.jimmy.demo.vo.EmployeeRoleVo" > insert into diary_employee_role (employeeId,roleId) values <foreach collection="roleList" item="item" index="index" separator="," > (#{employee.eid},#{item.id}) </foreach> </insert>
<a name="3ymrdx"></a>### 根据List<Object> 批量删除```sql<delete id="deleteBatchByCondition"> delete from BOM_PART_PARTS_P A where exists ( select 1 from( <foreach collection="list" item="item" index="index" separator="union all"> select B.PART_PARTS_CODE from BOM_PART_PARTS_P B where 1=1 and B.PART_CODE = #{item.partCode,jdbcType=VARCHAR} and B.PARENT_PART_CODE = #{item.parentPartCode,jdbcType=VARCHAR} and B.LINE_NO = #{item.lineNo,jdbcType=VARCHAR} and B.ACTIVATE = 0 </foreach> )S where A.PART_PARTS_CODE = S.PART_PARTS_CODE )</delete>