From the course: Advanced SQL for Data Science: Time Series

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Rank

Rank - SQL Tutorial

From the course: Advanced SQL for Data Science: Time Series

Start my 1-month free trial

Rank

- Now continuing from where we left off, let's look at a different kind of function. We're going to look at one called rank. We use rank when we want to know the relative order of a particular row relative to other rows. So for example, if we wanted to know the ranking of each row we could use the rank function and apply that rank function over the window that we have been defining before, which is basically by department ID. So, instead of returning a value that occurs in another row, rank will calculate an integer which indicates the relative order of a particular value in a series of rows. So let's execute. And what we have here is the value that is returned is a rank ordering. So if we had 10 distinct values and had them sorted from largest to smallest and they were all unique, each of them would be assigned a rank from one through 10. Now you'll notice here that the first two rows have the same value, so they have the same rank. And then we're followed by several rows that also…

Contents