gpt4 book ai didi

mysql - SQL-如何选择为所有模块注册的学生姓名?

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

学生

+------+-------+--------------------------------------+
| Sid | sName | content |
+------+-------+--------------------------------------+
| 1 | Tim | ... |
| 2 | boyo | ... |
| 3 | Carl | ... |
| 4 | Life | ... |
+------+-------+--------------------------------------+

模块

+------+-------+--------------------------------------+
| mID | mName | content |
+------+-------+--------------------------------------+
| 1 | Data | ... |
| 2 | IT | ... |
| 3 | Math | ... |
| | | ... |
+------+-------+--------------------------------------+

注册

+------+-------+--------------------------------------+
| sID | mID | content |
+------+-------+--------------------------------------+
| 1 | 1 | ... |
| 1 | 2 | ... |
| 1 | 3 | ... |
| 3 | 1 | ... |
+------+-------+--------------------------------------+

最佳答案

按学生对数据进行分组,并仅采用注册模块数与模块总数相同的学生

select s.sname
from students s
join Registration r on s.sid = r.sid
group by s.sname
having count(r.mid) = (select count(mid) from modules)

关于mysql - SQL-如何选择为所有模块注册的学生姓名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45982856/

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