MySQL Complex Inner Join查询获取错误

时间:2013-03-07 14:51:09

标签: mysql mysql-workbench

查询定义:
选择艺术等级为85或更高的学生

任何计算机课程的成绩均为85或更高
QUERY(在3节中解释是在MySQLWorkBench上执行的单个查询):

select Students.StudFirstName,Student_Schedules.Grade
from 
(Select Distinct Students.StudentID,Students.StudFirstName,Student_Schedules.Grade 
from (((Students

Inner Join Student_Schedules
On Student_Schedules.StudentID = Students.StudentID)

Inner Join Classes
On Classes.ClassID = Student_Schedules.ClassID)

Inner Join Subjects
On Subjects.SubjectID = Classes.SubjectID)

Inner Join Categories
On Subjects.CategoryID = Categories.CategoryID

where Categories.CategoryDescription = 'Art' and Student_Schedules.Grade >= 85)
            As Stud_Art


以上代码摘录了艺术等级为85或更高的学生

Inner Join

(Select Distinct Students.StudentID,Students.StudFirstName,Student_Schedules.Grade 
from (((Students

Inner Join Student_Schedules
On Student_Schedules.StudentID = Students.StudentID)

Inner Join Classes
On Classes.ClassID = Student_Schedules.ClassID)

Inner Join Subjects
On Subjects.SubjectID = Classes.SubjectID)

Inner Join Categories
On Subjects.CategoryID = Categories.CategoryID

WHERE Categories.CategoryDescription LIKE '%Computer%' AND Student_Schedules.Grade >=    85)

As Stud_CS


以上代码摘录了计算机等级为85或更高的学生

On Stud_CS.StudentID = Stud_Art.StudentID;


上面的代码与艺术和计算机上的StudentID相匹配


来自MySQLWorkBench的错误:
    错误代码:1054。“字段列表”中的未知列'Students.StudFirstName'

上述查询可以通过SubQuery技术解决,但我想了解内连接技术是如何实现的

1 个答案:

答案 0 :(得分:0)

您正在尝试检索Students.StudFirstName和Student_Schedules.Grade,但您的表别名是Stud_Art和Stud_CS。可能是问题吗?

我认为第一部分应该是这样的:

select Stud_Art.StudFirstName,Stud_Art.Grade