sql 无效标识符,使用别名

sql invalid identifier, using alias

select student.ID, course_id
from (
  select student.ID, course_id
  from student,takes 
  where student.id = takes.id
  group by student.ID,course_id
  having count(student.ID) >1
  )
group by student.id
having count(*)>2

我是 sql 的新手,正在为嵌套子查询苦苦挣扎。 这就是我所做的,试图找出谁至少重修过一次至少 3 门课程。它没有用。我知道这看起来也很奇怪......

完全披露:我还没有测试语法错误,但我确实看到了您的代码的两个主要问题。 A:你需要给你的子查询一个别名 B:您需要在子查询中使用变量名称以及外部查询中的新别名(请注意,我在内部查询中为 student.id 分配了 "student_id" 的别名)

select 
    retakes.student_id,
    retakes.course_id
from 
(
    select 
        student.ID student_id,
        course_id
    from student,takes 
    where student.id = takes.id
    group by student.ID, course_id
    having count(*) >1
) retakes
group by retakes.student_id
having count(*)>2

如果您在原始 post(或任何后续答案)中包含您遇到的错误,将会很有帮助。