Additional SQL Server features and topics not covered by specific categories
Subquery was the alias I gave. One more time:
select FilmLengthCategory, count(film_id) as CountOfFilms from (
select film_id
, title
, length
, rating
, case
when length between 0 and 59 then 'Less than 1 hour'
when length between 60 and 119 then '1 to 2 hours'
when length between 120 and 179 then '2 to 3 hours'
else 'over 3 hours'
end as FilmLengthCategory
from film ) AS SubQuery
GROUP BY FilmLengthCategory
ORDER BY CountOfFilms
If this would not work in PostgreSQL, try using ORDER BY 2. Everything else is very basic SQL so I assume it should work the same in any database (hopefully).