WIDTH_BUCKET()
WIDTH_BUCKET() is a SQL function in the Numeric Functions category. Creates equi-width histogram buckets. Returns the bucket number for each value. Oracle/PostgreSQL. The syntax is WIDTH_BUCKET(expression, min, max, num_buckets). It accepts expression, min, max, num_buckets. It returns bucket number. A typical example: SELECT name, salary, WIDTH_BUCKET(salary, 30000, 100000, 5) AS salary_bucket FROM employees; -- Buckets: 1=30k-44k, 2=44k-58k, 3=58k-72k, 4=72k-86k, 5=86k-100k -- Values outside range: bucket 0 (below) or num_buckets+1 (above) A close relative is ROUND(), which rounds a number to a specified number of decimal places. A close relative is ABS(), which returns the absolute (positive) value of a number. A close relative is CEIL() / CEILING(), which returns the smallest integer greater than or equal to a number (rounds up). More about this category: Mathematical functions — ROUND, ABS, CEIL, FLOOR, POWER, SQRT, MOD. Related Numeric Functions entries: ROUND(), ABS(), CEIL() / CEILING(), FLOOR(), POWER() / POW(), SQRT(), MOD(), GREATEST() / LEAST().