使用子查询获取排序后的数据
Using subqueries to obtain sorted data
因此,对于一项学校作业,我需要输出学生的姓氏和名字,以及已注册的前 8 名学生,并按此排序。我不会担心将它限制为 8(当其他一切正常时这很容易),但我需要弄清楚我做错了什么并且需要在这里做。这是我拥有的:
SELECT student.first_name, student.last_name
FROM student
WHERE student.student_id IN (SELECT enrollment.student_id
FROM enrollment
ORDER BY enrollment.enroll_date);
好吧,因为 oracle 实际上看到你的代码是这样的:
SELECT student.first_name, student.last_name
FROM student
WHERE student.student_id IN (
SELECT enrollment.student_id FROM
enrollment ) --where the ) should be!!!
ORDER BY enrollment.enroll_date --and this line just mess up the code delete this.
发生这种情况的原因在于您尝试 order by
的子查询。只需删除 order by
或在子查询之外使用它,错误就不会再发生了。
此外,当您使用 IN
时,在该子查询中使用 order by
没有任何意义。
因此,对于一项学校作业,我需要输出学生的姓氏和名字,以及已注册的前 8 名学生,并按此排序。我不会担心将它限制为 8(当其他一切正常时这很容易),但我需要弄清楚我做错了什么并且需要在这里做。这是我拥有的:
SELECT student.first_name, student.last_name
FROM student
WHERE student.student_id IN (SELECT enrollment.student_id
FROM enrollment
ORDER BY enrollment.enroll_date);
好吧,因为 oracle 实际上看到你的代码是这样的:
SELECT student.first_name, student.last_name
FROM student
WHERE student.student_id IN (
SELECT enrollment.student_id FROM
enrollment ) --where the ) should be!!!
ORDER BY enrollment.enroll_date --and this line just mess up the code delete this.
发生这种情况的原因在于您尝试 order by
的子查询。只需删除 order by
或在子查询之外使用它,错误就不会再发生了。
此外,当您使用 IN
时,在该子查询中使用 order by
没有任何意义。