我有一张table,结构如下:
create table student_course(
student_id integer,
course_id integer,
primary key (student_id, course_id)
);
这里是我的用例:选择某些课程的学生需要参加另一个辅助课程。例如,一个注册了 course_id
的 101
必须修一门额外的课程 course_id
的 300
,因为101太难了,他们应该同时上300的辅导课。
我需要创建一个sql查询,为选修本课程的学生添加额外的条目 student_course
表格;在本例中,为101到300的学生添加新行。
我现在正在使用 select * from students_course where course_id = 101
,然后导出此数据以更新101到300的注册学生。最后,我用101再次导入这些输出的学生。有没有更好的sql查询可以用来插入当前表中的数据?
1条答案
按热度按时间gk7wooem1#
您基本上需要将insert查询与select一起使用。请尝试以下查询:
注意:请确保您没有课程id为101且课程id为300的学生,否则此查询将不起作用。