sql 这几道题目的语句怎么写,研究了好几个星期马上要交了
来源:百度知道 编辑:UC知道 时间:2024/05/31 15:01:18
学生(学号,姓名,专业,年级,年龄)
Class(name: string, meets_at: time, room: string, fid: integer)
课程(课程名,上课时间,上课教室,教师编号)
Enrolled(snum: integer, cname: string)
选修(学号,课程名)
Faculty(fid: integer, fname: string, deptid: integer)
教师(教师编号,教师姓名,所在院系编号)
1. 找出选修了James所教课程的所有大三学生的名字。
2. 找出History专业或者选修了James所教课程的学生的最大的年龄。
4. 找出选修了两门在同一时间上课的课程的所有学生的名字。
5. 找出那些在所有的教室都上过课的教师的名字。
12. 对于出现在Student中的每个年龄值,找出其最常出现的年级。例如,如果一年级18岁的学生最多,就输出“18,一年级”。
研究了好几个星期马上要交了,我自己觉得问题是我不会把第一步求出来的SUM()或者是COUNT()里面的值再进行MAX.
总之是嵌套问题吧.
大概是这样写:【自己再检查一下语法 可能有手误】
1. 找出选修了James所教课程的所有大三学生的名字。
select sname from student a where a.level='大三' and a.snum in ( select b.snum from
Enrolled b,Class c,Faculty d
where b.cname=c.name and c.fid=d.fid and d.fname='James' )
2. 找出History专业或者选修了James所教课程的学生的最大的年龄。
select max(age) from ( select a.age from student a,Enrolled b,Class c,Faculty d
where a.snum=b.snum and b.cname=c.name and c.fid=d.fid and (d.fname='James'
or a.major='History'))
4. 找出选修了两门在同一时间上课的课程的所有学生的名字。
select a.sname from student a where snum in (select b.snum from Enrolled b,Enrolled c,Class d,Class e where
b.snum = c.snum and and b.cname<>c.cname and b.cname=d.name and c.cname=e.name and d.meets_at=e.meets_at)
5. 找出那些在所有的教室都上过课的教师的名字。
select fname from Faculty a , (select count(distinct room) as _count from class ) b, (select fid ,count(*) as _co