I want to do a nested aggregation where I can choose whether aggregate the max, min, or avg of a nested avg aggregation.
I want my result to look like this: (genre, MAX or MIN or AVG of nested AVG)
Current i have a nested aggregation query which only returns the Maximum average price of a genre, but i can't seem to also select the genre corresponding to that maximum.
Consider the table games(gameID, gameName, genre, price), disregard gameID and gameName.
The nested query i have right now:
SELECT MAX(avggenreprice) AS maxavg
FROM (
SELECT genre as subgenre, AVG(price) as avggenreprice
FROM games
GROUP BY
subgenre
) AS sub;
Example result of this query:
|maxavg|
| 368.22|
I want it to look like this
| genre | maxavg |
| Racer | 368.22 |
Ive tried :
SELECT sub.subgenre, MAX(avggenreprice) AS maxavg
FROM (
SELECT genre as subgenre, AVG(price) as avggenreprice
FROM games
GROUP BY
subgenre
) AS sub
;
But this just gives me error code 1140