The next of these window functions will look at is nn tile.
So nn tile is a function we could use.
Let's say we wanted to divide up salaries into quartiles and figure out which quartile each salary fit
into or which decimal tile.
Which percentage.
If we divided it into 100, we could do it as a percentage basis.
So the concept is we provide a number RN, and that's how many buckets that are values will be sorted
into.
And so within each partition, let's say we did four, we would have four buckets for salaries and then
it will return to us a number ranging from one up to four up to RN to say which quartile that we a given
value falls into.
So let me just show it.
Let's work on a new query that is a little less cluttered.
So I'm going to get rid of all this.
I'll keep employee number department in salary, but then what I'm going to do here is RN tile.
Let's do quartile.
Sure.
And tile.
And then we have to say over what are we going to do, the entire company or the entire table of employees?
Let's start there.
So we'll just say over and we'll order by salary descending and we'll call this one salary quartile.
Let's just call it caught quartile OC.
Let's run this.
And overall rank.
What is he complaining about?
Oh, duh, I'm ordering by there.
I can't do that because I got rid of that column I was ordering by.
Try it again.
So you'll see on the right side we have salary quartile that shows us if we're in the first quartile,
second, third or fourth for each row for that salary.
So down 31,000 up to 55,000.
That's the fourth quartile.
The first quartile in our example is 159,070 2000.
That's not saying the quartile stops here.
It's just with the rows that we currently have, that is the lowest number that is considered in that
first quartile.
So we could also do an example where we partition.
So this is for the entire company overall or the entire table.
At least here we'll do a partition by department.
And then we'll order by salary descending within the department and we'll call this department salary
quartile.
And I need a comma and I'm using quartile.
It's a common example we don't have to do for you could do whatever number of buckets you want.
And here we are within each department now we see that it's a little hard because it's not grouped by
or it's not ordered by department.
But if we look at this person, they're in sales 159,000, their first overall and also quartile one
overall and quartile one in their sales department.
But let's look at this person right here.
This person is in the second quartile overall for salary making 67,000.
But within engineering, they're one of the lower paid engineers on the team.
They are in the fourth bucket, the fourth quartile.
So that's entail, of course, you could break it up two different buckets.
You could work with different pieces of data and partition them using another column.
We just don't have much with our department salary employee number.
That's kind of all we got.
But it still illustrates how this works.
We break up a window into different buckets and then for each value, you tell me which of those buckets
we landed.