我基本上想要通过外键的条目列对特定查询结果进行排序。以下是我的表格:
class
------
classId
profId //Points to a profId from professor table
courseId //Points to a specific courseId from course table
semId //Points to a specific semId from semester table
professor
---------
profId
first //first name
last //last name
course
------
courseId
department //The `CMSC` in CMSC101
number //The `101` in CMSC101
title
semester
--------
semId
season //example: Spring, Summer, Fall
year
我希望它们可以按层次排序,也可以通过类列的列中的外键来命令。因此,我会SELECT
class
中的所有条目,并按此顺序对其进行排序:
答案 0 :(得分:2)
SELECT
Course.Department,
Course.Number,
Course.Section,
Professor.Last,
Professor.First,
Semester.Year,
Semester.Season
FROM Class
INNER JOIN Course ON Class.CourseID = Course.CourseID
INNER JOIN Professor ON Class.ProfID = Professor.ProfID
INNER JOIN Semester ON Class.SemID = Semester.SemID
ORDER BY
Course.Department,
Course.Number,
Course.Section,
Professor.Last,
Professor.First,
Semester.Year,
Semester.Season
列 不在<{1}}列表中供您排序,但在大多数情况下,将它们包含在那里是有意义的。
答案 1 :(得分:-1)