NTILE() Function

The NTILE(n) function is used to distribute the rows in an ordered partition into a specified number of groups or buckets. This is useful for categorizing data into quantiles, such as quartiles or deciles. For instance, to categorize employees into quartiles based on their salaries, you could write:

sqlCopy codeSELECT employee_id, salary, NTILE(4) OVER (ORDER BY salary) AS salary_quartile FROM employees;

This query divides the employees into four groups based on salary, effectively allowing for comparative analysis across different segments. Understanding how employees are distributed in terms of compensation helps organizations assess salary equity and performance across different quartiles.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *