Oracle
 sql >> Database >  >> RDS >> Oracle

Max di somma richiesta

SELECT q3.S_ID,
       q3.S_LAST,
       q3.S_FIRST,
      max( q3.Total Credits)
FROM
  (SELECT q2.S_ID,
          q2.S_LAST,
          q2.S_FIRST,
          sum(q1.CREDITS) Total Credits
   FROM
     (SELECT COURSE_NO,
             CREDITS
      FROM COURSE) q1
   JOIN
     (SELECT s.S_ID,
             s.S_LAST,
             s.S_FIRST,
             cs.COURSE_NO
      FROM STUDENT s
      JOIN ENROLLMENT e ON s.S_ID = e.S_ID
      JOIN COURSE_SECTION cs ON e.C_SEC_ID = cs.C_SEC_ID) q2 ON q1.COURSE_NO = q2.COURSE_NO
   GROUP BY q2.S_ID,
            q2.S_LAST,
            q2.S_FIRST) q3
GROUP BY q3.S_ID,
         q3.S_LAST,
         q3.S_FIRST;