I have a nested query which returns the totalFare of all passengers grouped by the different passenger types.
SELECT PASSNGR.type , sum(FARE.fee) AS totalFare
FROM Passenger AS PASSNGR
JOIN Fare AS FARE ON (PASSNGR.type = FARE.type)
GROUP BY PASSNGR.type
ORDER BY totalFare DESC
I am trying to understand how to select the row with the Max(totalFare). I have looked around but most are selecting the maximum from a defined table, where as I am using a nested query to generate the totalFare per passenger type.
I tried to nest another Select MAX(totalFare) before the initial select, but that only returns the value of the max not the type as well.
SELECT MAX(totalFare)
FROM (SELECT PASSNGR.type , sum(FARE.fee) AS totalFare
FROM Passenger AS PASSNGR
JOIN Fare AS FARE ON (PASSNGR.type = FARE.type)
GROUP BY PASSNGR.type ORDER BY totalFare)