Using MAX() and AVG() in the same query?

exercise: https://www.codecademy.com/paths/data-science/tracks/sql-intermediate/modules/dspath-sql-aggregates/lessons/aggregate-functions/exercises/avg

I want to query “Which category has the highest average downloads?”
Similarly, how can I submit one query that lists the averages of all the distinct categories in order from highest to lowest?

My guess for the first query was the following, but it yielded nothing:

SELECT category, MAX (AVG(downloads))
FROM fake_apps;

Thank you!

Hello @coderelinquisher welcome to the forums. For the second query, I think something like this might work:

SELECT category, AVG(downloads) as col2
FROM fake_apps
ORDER BY col2 DESC;

As for the first query, you could try using an aggregate table (using WITH).

2 Likes