Search⌘ K
AI Features

Binning

Explore how to divide data into meaningful ranges or bins using custom binning and percentile methods in SQL. This lesson helps you categorize values effectively, assign classifications like grades, and understand different binning strategies for clearer data insights and analysis.

Overview

Binning or bucketing, is a technique to divide a series of values into ranges for analysis or for visualization. For each range, we calculate the frequency—the number of values from the series that fit in this range. The ranges are often referred to as bins, buckets, or groups.

To demonstrate different binning techniques, we are going to use a table with student grades:

PostgreSQL
CREATE TABLE grades (
grade INT
);
INSERT INTO grades (grade) VALUES
(24),
(41), (45),
(54), (55), (56),
(61), (65), (62), (68),
(71), (72), (71), (71), (74), (76), (72), (77),
(82), (84), (82), (88), (89), (81), (82),
(90), (91), (94), (92),
(100)
;
SELECT * FROM grades;

We have 30 ...