原创

MySQL-EXISTS-INSERT-SELECT-插入时判重数据-INSERT SELECT WHERE NOT EXISTS


<insert id="addUserIntermediate4Exam">
INSERT INTO eduinp_user_intermediate(`container_id`, `implement_id`, `user_orgs`, `status`, `handling_status`, `handled_user_id`, `create_time`, `update_time`)
SELECT container_id, #{examId}, `user_orgs`, `status`, `handling_status`, `handled_user_id`, `create_time`, `update_time`
FROM eduinp_user_intermediate
WHERE container_id = #{containerId} AND id = #{id} AND NOT EXISTS (SELECT 1 FROM eduinp_user_intermediate WHERE implement_id = #{examId});
</insert>

好像只能在insert ... select ... 时可以加where
正文到此结束
本文目录