Histogram (Data Distribution)
Histogram (Data Distribution) is a SQL statement in the SELECT Queries category. Creates an equal-width histogram to understand data distribution across a numeric column. The syntax is SELECT width_bucket(col, min, max, buckets) AS bucket, COUNT(*) FROM table GROUP BY bucket ORDER BY bucket;. It returns histogram result. A typical example: SELECT CASE WHEN salary BETWEEN 0 AND 30000 THEN '0-30K' WHEN salary BETWEEN 30001 AND 50000 THEN '30K-50K' WHEN salary BETWEEN 50001 AND 80000 THEN '50K-80K' WHEN salary BETWEEN 80001 AND 120000 THEN '80K-120K' ELSE '120K+' END AS salary_range, COUNT(*) AS employee_count FROM employees GROUP BY salary_range ORDER BY salary_range; -- Shows salary distribution across the company -- Using NTILE for equal-height histogram: SELECT NTILE(5) OVER (ORDER BY salary) AS… A close relative is SELECT, which retrieves data from a table. The most fundamental SQL statement. A close relative is SELECT *, which selects all columns from a table.