我有以下數據庫:運動對羣體
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