gpt4 book ai didi

mysql查询查找具有类(class)组合的学生

转载 作者:行者123 更新时间:2023-11-29 12:10:28 25 4
gpt4 key购买 nike

我有一张包含 2 个字段的表。 Student_id 和 Course_id特定的 Student_ID 可以选修多门类(class),例如,学生 2 在下面的示例中选修类(class) 101 和 102,但学生 1 只选修 102

student_id  course_id
1 102
2 101
2 102
3 303

我如何查询正在修读类(class) 101 和 102 的学生?或者是考了 102 但没有考 101 的学生?

对各位专家来说可能是一个新手问题......

最佳答案

也许是这个?

Select * from tablename where (course_id = 101) OR (course_id = 102);

检查某人是否在 101 而不是 102

select * from tablename 
where (course_id = 101) and
(student_Id not in
(select Student_ID from tablename
where course_id =102));

检查是否有人同时存在:

select * from tablename 
where (course_id = 101) and
(student_Id in
(select student_Id from tablename
where course_id =102));

SQL fiddle

关于mysql查询查找具有类(class)组合的学生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30790826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com