Hi there, I am doing this exercise and blindly clicked next; but I want to know why:
SELECT price,
ROUND(AVG(downloads)),
COUNT(*)
FROM fake_apps
GROUP BY price
We can have ROUND(AVG(downlods)) ?
Also, if anyone would be kind enough to explain really quickly “having count” and how I can use it with variables, this would be a gem, thank you :).
https://www.codecademy.com/courses/learn-sql/lessons/aggregate-functions/exercises/having
You mean columns as opposed to variables?
So, with this query you’re looking at price, the average number of downloads (rounded), & the number of apps grouped by price and then you’re filtering out the price points that have more than 10 apps.
HAVING COUNT(*) > 10;
HAVING
filters groups (WHERE
filters rows) based on an aggregate.
round()
:
https://database.guide/how-round-works-in-sqlite/
HAVING
:
1 Like
How do you know all of this? It is so confusing haha.
Could you possibly explain how we can combine two aggregate functions into a single statement? THis part is pretty tricky for me.
Oh! Is ‘in each’ keyword for ‘group by’?
It definitely can be confusing. You’re not the first one to be confused by it. 
Practice, repetition. Plus, read up on how to use aggregate functions–including ROUND()
as well.
The instructions state that the query,
SELECT price,
ROUND(AVG(downloads)),
COUNT(*)
FROM fake_apps
GROUP BY price
HAVING COUNT(*) > 10;
‘…returns the average downloads (rounded) and the number of apps – at each price point.
However, certain price points don’t have very many apps, so their average downloads are less meaningful.
Add a HAVING
clause to restrict the query to price points that have more than 10 apps.’
2 Likes