PostgreSQLWindow FunctionsNTILE
CUME_DIST

NTILEWindow Functions

LAG

Divides the partition into n equal buckets.

Syntax

NTILE(n) OVER (w)

Example

Enter values below to update the example in real time.

employee_id
salary
quartile
employees
SELECT employee_id, salary,
       NTILE(4) OVER (ORDER BY salary DESC) AS quartile
FROM employees;