简单 SQL 查询语句语法错误
Simple SQL Query Statement syntax error
我是数据库新手,之前从未使用过 Access 2007,我在语法方面遇到了麻烦。这是信息
Teacher = [CourseN, Quarter,TeacherName]
Course = [CourseN,CourseName, Nunit)
Section = [CourseN, Quarter , DayTime, RoomN]/ Examples of DayTime: M2:00AM,
W4:50PM, and T8:00PM. Note that DayTime is represented as a string.
Student = [studentName, CourseN, Quarter]
问题
12.Use‘*’列出每门课程的CourseN、CourseName、Nunit、Quarter、TeacherName,按照CourseN升序、CourseName降序排列。
我的回答
SELECT CourseN, CourseName, Nunit, Quarter, TeacherName
FROM *
ORDER BY CourseN ASC, CourseName DESC;
但这给了我 FROM 子句错误,我该如何解决这个语法错误?还是我不能这样做?任何信息都会很棒,谢谢
编辑:我知道我可以这样做对吗?
SELECT C.CourseN, C.CourseName, C.Nunit, T.Quarter, T.TeacherName
FROM Course C, Teacher T
WHERE T.CourseN = C.CourseN
ORDER BY C.CourseN ASC, C.CourseName DESC;
您不能将 *
放在 FROM
子句中!您必须明确定义要使用的表。
再想一想:虽然您可以在 WHERE
子句中定义表之间的关系,但如果您在 FROM
子句中定义关系会更好(或至少更清楚),使用 INNER JOIN
:
select c.courseN, c. courseName, c.Nunit, t.quarter, t.teacherName
from course as c
inner join teacher as t on c.counrseN = t.courseN
我是数据库新手,之前从未使用过 Access 2007,我在语法方面遇到了麻烦。这是信息
Teacher = [CourseN, Quarter,TeacherName]
Course = [CourseN,CourseName, Nunit)
Section = [CourseN, Quarter , DayTime, RoomN]/ Examples of DayTime: M2:00AM,
W4:50PM, and T8:00PM. Note that DayTime is represented as a string.
Student = [studentName, CourseN, Quarter]
问题
12.Use‘*’列出每门课程的CourseN、CourseName、Nunit、Quarter、TeacherName,按照CourseN升序、CourseName降序排列。
我的回答
SELECT CourseN, CourseName, Nunit, Quarter, TeacherName
FROM *
ORDER BY CourseN ASC, CourseName DESC;
但这给了我 FROM 子句错误,我该如何解决这个语法错误?还是我不能这样做?任何信息都会很棒,谢谢
编辑:我知道我可以这样做对吗?
SELECT C.CourseN, C.CourseName, C.Nunit, T.Quarter, T.TeacherName
FROM Course C, Teacher T
WHERE T.CourseN = C.CourseN
ORDER BY C.CourseN ASC, C.CourseName DESC;
您不能将 *
放在 FROM
子句中!您必须明确定义要使用的表。
再想一想:虽然您可以在 WHERE
子句中定义表之间的关系,但如果您在 FROM
子句中定义关系会更好(或至少更清楚),使用 INNER JOIN
:
select c.courseN, c. courseName, c.Nunit, t.quarter, t.teacherName
from course as c
inner join teacher as t on c.counrseN = t.courseN