以下是我的查询基本上有一个学生分会表,其中包含学生课程信息,此表除了课程描述外还有我需要的一切。这包含在课程表中。出于某种原因,我似乎只能从studentsection表中获取条目,我尝试的每个查询都从课程表中获取所有内容。非常感谢任何帮助!
select distinct studentid
, s.deptnum
, s.coursenum
, coursedesc
, sectionnum
, quarter
, grade
from studentsection c
left
join course c
on s.deptnum = c.deptnum
where exists( select deptnum from course)
order
by studentid
, quarter
, grade;
以下是我的表格定义:
create table StudentSection(
studentID int,
deptNum char(4),
courseNum char(3),
sectionNum char(2),
quarter char(3),
grade varchar(1),
constraint studentSection_PK primary key(studentID, deptNum, courseNum, sectionNum, quarter),
constraint studentSection_section_FK foreign key (deptNum, courseNum, sectionNum, quarter) references Section(deptNum, courseNum, sectionNum, quarter)
)
CREATE TABLE Course (
deptNum char(4),
courseNum char(3),
courseDesc varchar(50) NOT NULL,
creditHrs integer,
CONSTRAINT course_PK PRIMARY KEY (deptNum, courseNum),
CONSTRAINT course_department_FK FOREIGN KEY (deptNum) REFERENCES department(deptNum))
CREATE TABLE Section (
deptNum char(4),
courseNum char(3),
sectionNum char(2),
quarter char(3),
instructor varchar(20),
CONSTRAINT section_PK PRIMARY KEY (deptNum, courseNum, sectionNum, quarter),
CONSTRAINT section_course_FK FOREIGN KEY (deptNum, courseNum) REFERENCES course(deptNum, courseNum));
答案 0 :(得分:0)
我不确定我的问题是否正确,但您是否尝试了inner join
?