AS rowNumber, RANK() OVER (ORDER BY employeeCount) AS rankNumber, DENSE_RANK() OVER (ORDER BY employeeCount) AS denseRankNumber, CUME_DIST() OVER (ORDER BY employeeCount) AS cumeDist FROM (SELECT o.officeCode, city, COUNT(*) AS employeeCount FROM offices o JOIN employees e ON o.officeCode = e.officeCode GROUP BY o.officeCode, city) AS oe;