如何在SQL中处理此查询? [关闭]

问题描述 投票:0回答:1
select course_id
from section as S
where semester = ’Fall’ and year= 2009 
  and exists (select *
              from section as T
              where semester = ’Spring’ and year = 2010 and S.course_id = T.course id);

DBMS如何在内部执行此类查询?我假设内部和外部子查询是独立执行的。我的假设正确吗?如果是,那么子查询在这里如何关联->“ S.course_id = T.course id”?内部关联如何引用外部关联?

这是部分关系的模式:

create table section
(
    course_id varchar (8),
    sec_id varchar (8),
    semester varchar (6),
    year numeric (4,0),
    building varchar (15),
    room number varchar (7),
    time slot_id varchar (4),

    primary key (course_id, sec_id, semester, year),
    foreign key (course_id) references course
);
mysql sql database sqlite rdbms
1个回答
0
投票
这是您的查询(尽管我已经更改了别名并更广泛地使用它们):
© www.soinside.com 2019 - 2024. All rights reserved.