> Why we cannot replace `COUNT(*)` by `3`?

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



SELECT price
       ROUND(AVG(downloads)),
       COUNT(*)
FROM fake_apps
GROUP BY price
HAVING  COUNT(*) > 10;

In 6th row of the query above, Why we can not replace COUNT(*) by 3, so our code will be something like this :beginner: :beginner:

SELECT price,
       ROUND(AVG(downloads)),
       COUNT(*)
FROM fake_apps
GROUP BY price
HAVING  3 > 10;

Why we cannot replace COUNT(*) by 3?

Because it’s an aggregate. You can’t use ordinals with the HAVING clause. You can use it with ORDER BY & GROUP BY.
HAVING filters groups (WHERE filters rows).

https://stackoverflow.com/questions/2253040/benefits-of-using-sql-ordinal-position-notation

3 Likes