Complete worked example
sql
WITH counts AS (SELECT country,COUNT(*) AS n FROM roles WHERE active=1 GROUP BY country)
SELECT country,n,ROUND(100.0*n/NULLIF(SUM(n) OVER (),0),2) AS share
FROM counts ORDER BY country;- Reasoning
- Six active roles supply the worked denominator.