您好我的情况是用户被分配到多对多关系的项目。 每次我添加新用户我希望为他复制现有的任务,在其他情况下 将他分配给所有项目的话,也分配了其他用户。 目前我复制整个表,然后重新插入如下,但想知道 如果可以在一个查询中排序?
# tmp_assignments already exist and have same fields as assignment
truncate tmp_assignments;
INSERT tmp_assignments SELECT * FROM assignments;
# 38 is new user id
insert into assignments (project,user)
select a.project,38
from tmp_assignments as a group by project;
答案 0 :(得分:2)
刚刚做的问题是什么:
insert into assignments (project, user) select project, 38 from assignments group by project