对于以下代码,我得到此错误。
无效的标识符
有什么建议吗?
SELECT
subjects.neptuncode AS "neptuncode",
subjects.subjectname AS "subjectname",
enrollments.examdate AS "examdate"
FROM
subjects, enrollments
LEFT OUTER JOIN
enrollments ON enrollments.subject = subjects.subject_ID
HAVING
COUNT(enrollments.enrollmentdate) = 1
ORDER BY
subjects.neptuncode, subjects.subjectname, enrollments.examdate;
答案 0 :(得分:2)
更改此行
FROM subjects, enrollments
到
FROM subjects
您不应混用旧式的联接(用逗号分隔)和显式联接。确实,您不应该使用逗号分隔的联接,因为许多年前,它们实际上已被替换。
答案 1 :(得分:1)
FROM subjects, enrollments
有问题。
将其更改为FROM subjects
-问题已解决。
答案 2 :(得分:1)
我认为您要查询的是:
SELECT s.neptuncode, s.subjectname, MAX(e.examdate) as "examdate"
FROM subjects s JOIN
enrollments e
ON e.subject = s.subject_ID
GROUP BY s.neptuncode, s.subjectname
HAVING COUNT(*) = 1
ORDER BY s.neptuncode, s.subjectname;
这将返回只有一个注册者的科目的考试日期。
注意:
FROM
子句中使用逗号。 始终使用正确的显式JOIN
语法。LEFT JOIN
。您的HAVING
子句建议您只需要一个匹配项。GROUP BY
; HAVING
假设您要汇总。ORDER BY
中包括考试日期。