【发布时间】:2018-12-08 18:53:20
【问题描述】:
我试图找出哪些学校的学生在 2018 年没有完成考试。所以我设置了 3 个表格:ExamInfo、ExamEntry 和 Students。我将尝试使用ExamInfo 表从Students 表中获取信息,但我显然只想要2018 年未完成考试的学生信息。注意:我正在寻找参加过的学生,虽然没有完成考试,但通过这个特定的考试,您可以将完成的考试视为通过考试。
在ExamInfo 内我有列:
ExamInfo_Date --when exam took place, using to get year() condition
ExamInfo_ExamNo --unique student exam ID used to connect with other tables
ExamInfo_Completed --1 if completed, 0 if not.
...
ExamEntry内有相关栏目:
ExamEntry_ExamNo --connected to ExamInfo table
ExamEntry_StudentId --unique studentId used to connect to Students table
ExamEntry_Date -- this is same as ExamInfo_Date if any relevance.
...
在Students 内我有以下列:
Students_Id --this is related to ExamEntry_StudentId, PRIMARY KEY
Students_School --this is the school of which I wish to be my output.
...
我希望我的输出只是列出所有有学生在 2018 年未完成考试的学校。虽然我的问题是从 ExamInfo 表中查找学生未完成考试的学校.
到目前为止,我已经:
SELECT a.Students_School, YEAR(l.ExamInfo_Date), l.ExamInfo_Completed
FROM ExamInfo l ??JOIN?? Students a
WHERE YEAR(l.ExamInfo_Date) = 2018
AND l.ExamInfo_Completed = 0
;
我什至不确定是否需要查看ExamEntry 表。我确定我打算使用连接,但不确定如何正确使用它。此外,对于我的 3 个不同的 SELECT 列,我只希望输出 Students_School 列:
Students_School
---------------
Applederry
Barnet Boys
...
【问题讨论】:
-
和那个连接中的 ON 子句?
标签: mysql sql join foreign-keys primary-key