题目1:显示各门课程的考场数目和可容纳的考生
各数据表结构如下:
表1:课程表 TC
cid 课程id
cname 课程名
Ctype 考试方式
表2:考场表 TR
Roomed 考场id
address 考场地址
Contain 容纳人数
表3:考场课程对应表 TCR
cid 课程id
roomId 考场id题目2:显示考试安排有冲突的考生及考试课程和时间
所谓有冲突,就是指一个考生同一时间(或考试时间有交集)安排了两门及两门以上的考试
表1:课程表 TC
cid 课程id
cname 课程名
Ctype 考试方式
表2:考试表TE
eId 考试id
cid 课程id
beginTime 开始时间
endTime 结束时间
表3:考试安排表TSE
studentId 学生id
examId 考试id以上是一公司发来的题目,做好了才有面试机会,但我没学过SQL,感谢好心人先帮我过了这一关 ,感激不尽
各数据表结构如下:
表1:课程表 TC
cid 课程id
cname 课程名
Ctype 考试方式
表2:考场表 TR
Roomed 考场id
address 考场地址
Contain 容纳人数
表3:考场课程对应表 TCR
cid 课程id
roomId 考场id题目2:显示考试安排有冲突的考生及考试课程和时间
所谓有冲突,就是指一个考生同一时间(或考试时间有交集)安排了两门及两门以上的考试
表1:课程表 TC
cid 课程id
cname 课程名
Ctype 考试方式
表2:考试表TE
eId 考试id
cid 课程id
beginTime 开始时间
endTime 结束时间
表3:考试安排表TSE
studentId 学生id
examId 考试id以上是一公司发来的题目,做好了才有面试机会,但我没学过SQL,感谢好心人先帮我过了这一关 ,感激不尽
t1.cname as 课程名,
count(t2.roomid) as 考场数目,
sum(t3.contain) as 可容纳考生
from TC t1, tcr t2, TR t3
where t1.cid = t2.cid
and t2.roomid = t3.roomid
group by t1.cid, t1.cname;2:
select a.studentid, a.cid, a.examid, c.cname, a.begintime, a.endtime
from (select t1.studentID, t1.examID, t2.beginTime, t2.endTime, t2.cid
from TSe t1, TE t2
where t1.examID = t2.eID) a,
(select t1.studentID, t1.examID, t2.beginTime, t2.endTime, t2.cid
from TSe t1, TE t2
where t1.examID = t2.eID) b,
tc c
where a.studentID = b.studentID
and a.examID <> b.examID
and c.cid = a.cid(+)
and (a.beginTime <= b.beginTime and b.begintime < a.endTime)unionselect b.studentid, b.cid, b.examid, c.cname, b.begintime, b.endtime
from (select t1.studentID, t1.examID, t2.beginTime, t2.endTime, t2.cid
from TSe t1, TE t2
where t1.examID = t2.eID) a,
(select t1.studentID, t1.examID, t2.beginTime, t2.endTime, t2.cid
from TSe t1, TE t2
where t1.examID = t2.eID) b,
tc c
where a.studentID = b.studentID
and a.examID <> b.examID
and c.cid = b.cid(+)
and (a.beginTime <= b.beginTime and b.begintime < a.endTime)