From the course: SQL for Exploratory Data Analysis Essential Training
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Calculating histograms - PostgreSQL Tutorial
From the course: SQL for Exploratory Data Analysis Essential Training
Calculating histograms
- [Instructor] Now that we know how to partition data, let's calculate histograms. We want to list the bucket_floor and the average cost of insuring a person in each bucket. Let's start by creating a select statement. With the bucket logic from the previous lesson on creating partitions or buckets, we know that we can use this SQL statement to create bucket_floors for each age. Since we don't need the buckets enumerated, we can remove the bucket calculation and keep just the bucket_floor. The next thing we want to do is average the cost of insuring each person. Assuming the cost of each person is in the column, annual insurance, we'll add AVG(annual_cost). Since average is an aggregate function, and we want to get the averages for subsets of the whole table, we'll need to have a group by clause. So let's add that too, and to make sure the results are listed in increasing order, we can order by Bucket_floor. So the final statement includes selecting two values, the bucket_floor and the…