NTILE and PERCENT_RANK window functions
Compensation review prep — rank our 8 cost centers by 2025 YTD OpEx into quartiles, and give me each CC's percent rank. Columns: `cost_center_name`, `total_opex`, `quartile` (1 = highest spenders), `percent_rank`. Posted only.
Each hint you reveal reduces the XP you can earn. Try the query first.
Aggregate OpEx per cost center for 2025 in a subquery.
`NTILE(4) OVER (ORDER BY total_opex DESC)` for quartiles (1 = top).
`PERCENT_RANK() OVER (ORDER BY total_opex DESC)` for the continuous rank (0 = top, 1 = bottom).