gpt4 book ai didi

sql - MySQL - 我怎样才能得到名字为约翰的老师教过的所有学生的名字?

转载 作者:搜寻专家 更新时间:2023-10-30 21:48:24 25 4
gpt4 key购买 nike

我怎样才能得到名字为 John 的老师教过的所有学生的名字?

学生

id
name

student_has_teacher

teacher_id
student_id

老师

id
name

最佳答案

你必须使用 Inner Joins .内部联接通过基于联接谓词组合两个表的列值来创建新的结果表。您的查询可能看起来像这样:

SELECT      student.name
FROM student
INNER JOIN student_has_teacher ON (student_has_teacher.student_id = student.id)
INNER JOIN teacher ON (teacher.id = student_has_teacher.teacher_id)
WHERE teacher.name = 'John';

关于sql - MySQL - 我怎样才能得到名字为约翰的老师教过的所有学生的名字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3396033/

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