我有2个表:progress
和student
。 progress
包含字段semester
,idStudent
,hasFirstAttestation
和hasSecondAttestation
。
我需要从progress
获得那些学生最长学期且{Attestation = 0}的idStudent
。
以下是我的查询示例,但它不起作用:
SELECT progress.idStudent FROM monitoring.progress
WHERE hasFirstAttestation = 0 AND hasSecondAttestation = 0
AND semester =
(SELECT MAX(`semester`)
FROM monitoring.progress WHERE progress.idStudent = student.idStudent);
答案 0 :(得分:2)
我想你忘了在FROM Clause中提到连接表
SELECT idStudent
FROM monitoring.progress
WHERE hasFirstAttestation = 0 AND hasSecondAttestation = 0
AND semester = (SELECT MAX(semester) FROM monitoring.progress, monitoring.student
WHERE progress.idStudent = student.idStudent);
答案 1 :(得分:0)
SELECT progress.idstudent
FROM monitoring.progress
WHERE hasfirstattestation = 0
AND hassecondattestation = 0
AND semester = (SELECT Max(`semester`)
FROM monitoring.progress,monitoring.student
WHERE progress.idstudent = student.idstudent);