From the course: Intermediate SQL for Data Scientists (2021)

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

WIDTH_BUCKET and CUME_DIST

WIDTH_BUCKET and CUME_DIST

- [Instructor] When we work with windows functions, and we want to say pull up, say the top 10 items in a group or in a result set, the rank function could be used for that or is there some other ways we could do that for say by ordering or by using perch Festo only, but those don't work so well when we want to have a relative sort of calculation, like let's find the first 1% or top 10%. So if you want to work with rankings, but with percentages, there are a couple of window functions that come in handy. One is the width bucket, and the other is the cumulative distribution. So, let's take a look at the width bucket, and what the width bucket does is it allows you to say, identify, you know, if you divided this list into a certain number of buckets and they were in order like in tile, and you wanted to figure out which one does it drop into, the width bucket can help with that. Let's take a look at selecting our standard set…

Contents