嵌套的子查询,比较日期

时间:2016-10-13 17:59:43

标签: mysql sql

这是对的吗?我觉得我的逻辑不在这里,但我需要列出的学生比至少一名注册了“IT'部。

SELECT studentid, year
FROM enrolled, course
WHERE program = 'IT' and year >= ALL (
      SELECT year FROM enrolled);


enrolled(studentid, courseID, year)
course(courseid, department)

我相信一切都是正确的,除了那里的部分

抱歉,我给出了错误的架构,假设是来自

学生(sid,已开始,计划)

但我相信它现在适用于此,谢谢

SELECT sid, started
FROM student 
WHERE started > (
  SELECT MIN(started)
  FROM student
  WHERE program = 'IT');

1 个答案:

答案 0 :(得分:0)

采取步骤

第一个进入" IT" (猜测有一个名为program的列)

SELECT MIN(year)
FROM enrolled
WHERE program = 'IT'

列出的学生比至少一名注册了IT' IT'部。

SELECT studentid, year
FROM enrolled 
WHERE year > (
  SELECT MIN(year)
  FROM enrolled
  WHERE program = 'IT'
)