gpt4 book ai didi

mysql - 如何返回每个组中存在的所有行?

转载 作者:行者123 更新时间:2023-11-29 22:41:31 25 4
gpt4 key购买 nike

编辑: This是数据库。问题是:

Find the course title which all the students whom their advisor is professor Katz took that course.

我想解决这个问题:

1) 查找 Katz 教授的 ID。

2) 使用该 ID 查找 Katz 教授建议的学生的 ID。

3) 使用找到的学生 ID,查找 Katz 教授的顾问所修读的所有类(class)。

4) 按学生 ID 对结果进行分组,并获取每个组中存在的行,从而找到 Katz 教授的所有学生所修读的类(class)。

我无法执行步骤 4。

<小时/>

如何从分组表中返回所有行,其中每个返回的行都存在于表的每个组中?

最佳答案

SELECT Title 
FROM Course INNER JOIN Takes
ON Course.Course_ID = Takes.Course_ID
WHERE Takes.ID IN
(SELECT Student.Id
FROM Student INNER JOIN advisor ON Students.ID = Advisor.s_ID
INNER JOIN instructor ON Advisor.i_ID = Instructor.ID
WHERE Instructor.Name = 'Prof.Katz' )

关于mysql - 如何返回每个组中存在的所有行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29319921/

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