Analytical Functions in SQL . Part 1

Hoda Saiful
Jul 1, 2021

--

Rank function in SQL assigns a RANK to a column value based on its weight.

To illustrate, I use the below data set that contains columns — educational courses, category, quantity sold .

Problem Statement : Rank the 10 least sold products

RANK Function

There is a tie for the 3rd, 6th and 8th spot, also there are no 4th and 7th spots

DENSE RANK Function

Use Dense Rank when you do NOT want gaps .

There is a tie for the 3rd, 5th and 6th spots however there is no gap in the sequence unlike Rank.

ROW_NUMBER Function

when you do NOT want a tie, use ROW_NUMBER

A unique rank is assigned to every row.

--

--

Hoda Saiful
Hoda Saiful

Written by Hoda Saiful

When I have the time to write

No responses yet