В запросе должны быть указаны имя студента и средний балл.
Даны следующие таблицы:
раздел:
CREATE TABLE `Section` (
`ID` int(11) NOT NULL,
`Semester` varchar(45) DEFAULT NULL,
`Room` varchar(45) DEFAULT NULL,
`Instructor_ID` int(11) NOT NULL,
`Course_ID` int(11) NOT NULL,
PRIMARY KEY (`ID`),
KEY `fk_Section_Instructor_idx` (`Instructor_ID`),
KEY `fk_Section_Course1_idx` (`Course_ID`),
CONSTRAINT `fk_Section_Course1` FOREIGN KEY (`Course_ID`) REFERENCES `Course` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_Section_Instructor` FOREIGN KEY (`Instructor_ID`) REFERENCES `Instructor` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `Section` VALUES (1,'Fa17','828',1,1),(2,'Fa17','828',2,3),(3,'Fa17','829',1,4),(4,'Fa17','829',4,5),(5,'Sp18','828',1,1),(6,'Sp18','829',1,2),(7,'Sp18','828',3,4),(8,'Sp18','828',4,5);
курс:
DROP TABLE IF EXISTS `Course`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `Course` (
`ID` int(11) NOT NULL,
`Title` varchar(45) DEFAULT NULL,
`Description` text,
`Units` int(11) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `Course` VALUES (1,'CIS-15','Cloud Programming in Python',4),(2,'CIS-54','Relational Databases',4),(3,'CIS-81','Introduction to Networking',4),(4,'CIS-75','Introduction to Computer Security',3),(5,'CIS-90','Introduction to Linux',3);
регистрация:
CREATE TABLE `Registration` (
`Section_ID` int(11) NOT NULL,
`Student_ID` int(11) NOT NULL,
`Grade` int(11) DEFAULT NULL,
PRIMARY KEY (`Section_ID`,`Student_ID`),
KEY `fk_Section_has_Student_Student1_idx` (`Student_ID`),
KEY `fk_Section_has_Student_Section1_idx` (`Section_ID`),
CONSTRAINT `fk_Section_has_Student_Section1` FOREIGN KEY (`Section_ID`) REFERENCES `Section` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_Section_has_Student_Student1` FOREIGN KEY (`Student_ID`) REFERENCES `Student` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `Registration` VALUES (1,1,4),(1,2,4),(2,2,3),(3,3,2),(4,1,3),(4,3,3),(5,3,NULL),(5,4,NULL),(6,1,NULL),(6,2,NULL),(7,1,NULL),(7,4,NULL),(8,2,NULL),(8,3,NULL);
студент:
CREATE TABLE `Student` (
`ID` int(11) NOT NULL,
`Name` varchar(45) DEFAULT NULL,
`Email` varchar(45) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `Student` VALUES (1,'Steve Inskeep','steve@xyz.edu'),(2,'Rene Montaign','rene@xyz.edu'),(3,'David Green','david@xyz.edu'),(4,'Rachel Martin','rachel@xyz.edu');
Я попробовал этот код, попробовал это и получил бессмысленный вывод.Я довольно растерян
SELECT student.Name, (sum( registration.grade * course.units) /
sum(course.units)
) as GPA FROM registration
join student on registration.student_ID = student.id join section on section.ID = registration.section_ID
join course on section.course_ID = course.ID
group by registration.student_ID ;
ГПД кажется неправильным, потому что 
Возвращенный результат по предложению @Barbaros Özhan, а также по аналогичным решенияммое собственное:
'1', 'Steve Inskeep', '1.7857'
в качестве первого возвращенного ряда.
, но, очевидно, из-за того, что вы смотрите на регистрационную таблицу Student # 1не имеет 1.7857 ГПД.
Редактировать: Ответ Гордона Линоффа:
select student.Name,
(sum( registration.grade * course.units) /
sum( case when registration.grade is not null then course.units end )
) as GPA
from registration join
student
on registration.student_ID = student.id join
section
on section.ID = registration.section_ID join
course
on section.course_ID = course.ID
group by student.ID ;