Grouping and Ungrouping in SQL
Example specifying EXAM_MARK in place of COURSE in the main FROM clause.
Example: Obtaining C_ER2 from EXAM_MARK
TABLE (SELECT DISTINCT StudentId, Mark
FROM EXAM_MARK AS EM2
WHERE EM1.CourseId = EM2.CourseId)
AS ROW ( StudentId SID, Mark INTEGER ) MULTISET )
FROM EXAM_MARK AS EM
Figure shows the result, named C_ER2 for convenience. It differs from the C_ER of Figure 5.3 only in the absence of a row for course C4, whose exam nobody sat.
Figure: Intermediate result C_ER2