Max of sum query

前端 未结 5 1880
天涯浪人
天涯浪人 2021-01-27 09:48

I\'m trying to write a query that will list student(s) enrolled with the maximum total credit points.

Here is my query:

    SELECT s.S_ID,
       s.S_LAS         


        
5条回答
  •  执笔经年
    2021-01-27 10:04

    Removing all the "noise" your query become

    SELECT s.S_ID, s.S_LAST, s.S_FIRST, s."Total Credits"
    FROM
      (SELECT ...
       FROM (...) q1
       JOIN (...) q2
      ) q3
    GROUP BY s.S_ID, s.S_LAST, s.S_FIRST, s."Total Credits"
    WHERE "Total Credits" = max("Total Credits");
    

    It's easy to see that s is not visible from your main query, also in the WHERE condition you're confronting a detail with an aggregation, that's not possible (at least not that way)

提交回复
热议问题