我有以下数据库:运动对群体
Prof(profBadge, profName, Department) Course(courseCod, courseName, profBadge, area) Class(classCode, date, courseCod, numberOfStudents)
并提出以下要求: 对于谁只在该地区的数据库课程显示工号和课程其中最高平均每位教授学生的。
Create view badgeList(profBadge, courseCod) as
SELECT DISTINCT profBadge, courseCod
FROM Coure
WHERE (profBadge NOT IN (SELECT profBadge
FROM Course
WHERE Area <> 'database'));
Create view avgLessons(AvgStud, courseCod) as
SELECT AVG(numberOfStudents), courseCod
FROM class
GROUP BY courseCod;
Create view MaxStudent(maxStu, profBadge) as
select max(med.avgStud), el.profBadge
from avgLessons med, badgeList el
where med.courseCod= el.courseCod
group by el.profBadge;
select DISTINCT MS.profBadge, MS.MAXSTU, Corso.CODCORSO
from MaxStudent MS, course, class
where MS.profBadge = course.profBadge and MS.maxStu = class.numberOfStudents and course.courseCod = class.courseCod;`
将其分解成部分。首先,你如何找到平均学生人数最多的课程?那么你如何加入到数据集并显示“数据库”课程的徽章和课程编号? – xQbert
但是,如果我找到最高编号的课程,我会失去其他课程的信息,或者不是?我需要为每位教授 –
找到平均学生人数最多的课程,因此在该计算中包含一组在profbadge上的小组。并使用徽章和课程加入。我试图避免的是为你写答案,而是引导你尝试自己尝试解决问题的方法。那老人教导人们为了生活而吃鱼,让他们吃一天他们吃的鱼。不要吃整个大象,每次只吃一口,看看它是如何结合在一起的。分解为组成部分的复杂事物变得简单,当您将组件重新放回时,它不再复杂。 – xQbert