查询错误
SELECT Student.S_ID, Student.First_Name, Student.Surname,
MAX(New_Models.Date_Issued) AS Last_Course_Date,
MAX(New_Models.Issue) AS Last_Issue,
MAX(New_Models.Model_ID) AS Last_Model_ID,
Student.Course_Level AS No_Training_Courses,
**COUNT(Exam_Student.Exam_ID) AS Final_Exam_Level**
FROM New_Models, Model_Student, Student, Exams, Exam_Student
WHERE New_Models.Model_ID=Model_Student.Model_ID
AND Student.S_ID=Model_Student.S_ID
AND (Student.S_ID)=Exam_Student.S_ID
AND ((Exams.Exam_ID)=Exam_Student.Exam_ID)
AND (Exams.Date_Taken)<=#12/31/2010#
GROUP BY Student.S_ID, First_Name, Surname, S.Course_Level
ORDER BY Student.S_ID, MAX(New_Models.Model_ID) DESC;
除 COUNT 命令外,所有结果均按要求显示。当与应该出现的实际结果进行比较时,只有第一个单元格不同并且是错误的。 应该计算学生完成了多少次考试。
我可以回答任何问题,等待您的帮助。
SELECT
Student.S_ID,
Student.first_name,
Student.surname,
MAX(new_models.date_issued) AS last_course_date,
MAX(new_models.issue) AS last_issue,
MAX(new_models.model_id) AS last_model_id,
Student.course_level AS no_training_courses
FROM
new_models,
Student,
Model_Student
WHERE
new_models.model_id = Model_Student.model_id
AND Student.S_id = Model_Student.S_id
AND *strong text*Exam_ID IN (
SELECT COUNT(Exam_Student.Exam_id) AS Final_Exam_Level
FROM
Exams,
Exam_Student,
Student
WHERE
Student.S_ID = Exam_Student.S_ID
AND exams.date_taken <=#12/31/2010#
Group by Student.S_ID)
GROUP BY
Student.S_ID,
first_name,
surname,
Student.Course_level
ORDER BY
Student.S_id,
MAX(new_models.model_id) DESC;
我不能使用 INNER JOIN 所以,我想知道可以完成类似上面的事情。但是,我不知道如何进行子查询!
SELECT Student.S_ID, Student.First_Name, Student.Surname,
MAX(New_Models.Date_Issued) AS Last_Course_Date,
MAX(New_Models.Issue) AS Last_Issue,
MAX(New_Models.Model_ID) AS Last_Model_ID,
Student.Course_Level AS No_Training_Courses,
**COUNT(Exam_Student.Exam_ID) AS Final_Exam_Level**
FROM New_Models, Model_Student, Student, Exams, Exam_Student
WHERE New_Models.Model_ID=Model_Student.Model_ID
AND Student.S_ID=Model_Student.S_ID
AND (Student.S_ID)=Exam_Student.S_ID
AND ((Exams.Exam_ID)=Exam_Student.Exam_ID)
AND (Exams.Date_Taken)<=#12/31/2010#
GROUP BY Student.S_ID, First_Name, Surname, S.Course_Level
ORDER BY Student.S_ID, MAX(New_Models.Model_ID) DESC;
All the result appear as required except the COUNT command. When comparing with actual result whihc should come only the first cell differs and is wrong.
It should be counting how many exams has the student done.
I can answer any questions, will be waiting for your help.
SELECT
Student.S_ID,
Student.first_name,
Student.surname,
MAX(new_models.date_issued) AS last_course_date,
MAX(new_models.issue) AS last_issue,
MAX(new_models.model_id) AS last_model_id,
Student.course_level AS no_training_courses
FROM
new_models,
Student,
Model_Student
WHERE
new_models.model_id = Model_Student.model_id
AND Student.S_id = Model_Student.S_id
AND *strong text*Exam_ID IN (
SELECT COUNT(Exam_Student.Exam_id) AS Final_Exam_Level
FROM
Exams,
Exam_Student,
Student
WHERE
Student.S_ID = Exam_Student.S_ID
AND exams.date_taken <=#12/31/2010#
Group by Student.S_ID)
GROUP BY
Student.S_ID,
first_name,
surname,
Student.Course_level
ORDER BY
Student.S_id,
MAX(new_models.model_id) DESC;
I cannot use INNER JOIN so, I was wondering that something like the above can be done. However, I dont know how to do the subquery!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种可能有帮助的方法是简单地在计数上创建一个子查询,然后连接到该子查询。
我还建议使用 ANSI-92 样式连接
One approach that may help is to simply create a subquery on the Counts and then join to that.
I also recommend using ANSI-92 style joins
我猜测没有看到示例数据,但也许可以尝试这个,更改
为
如果这没有帮助,您将需要发布一些示例数据以及预期和实际结果以供某人帮助。
I'm guessing without seeing example data but maybe try this, change
to
If this does not help you will need to post some example data with expected and actual results for someone to help.