NTILE, FIRST_VALUE & frames
◈ 2 cardsBuckets, percentiles, and pulling a value from across the window.
More of the window toolkit
ntile(n)— split the ordered rows intonroughly equal buckets (quartiles, deciles…)first_value(expr)/last_value(expr)— the value from the first/last row of the window framepercent_rank(),cume_dist()— relative standing within the partition
The frame controls which rows a window sees. With an ORDER BY, the default frame runs from the start of the partition to the current row — so first_value(salary) OVER (PARTITION BY dept ORDER BY salary DESC) is the top salary in each department.