Let’s say I have a simple table CITY with ID, NAME, POPULATION columns I wanna know what is the percentage of cities with > 10000 population. I can do it with
select count(*) / (select count(*) from CITY) * 100
from CITY
where population > 10000
or like this
select count(case when population > 100000 then 1 else null end) / count(*) * 100
from CITY
but I was that it's appropriate to use a window function for that. How? When I do something like
select count(*) / sum(count(*)) over () * 100
from CITY
where population > 100000
I get 100 cause over() counts just the remaining rows. So, the question is: how to implement a widow function for counting percentage with condition?