Ranking the rows using ROW_NUMBER()

Hi Guys, here i m going to explain how you can give rank to the rows on the basis of column's information and by creating Partition.

suppose you have a table, like:-

M_Emp

EmpId EmpName
E001GAGAN
E001GAGAN
E001GAGAN
E002AMAN
E002AMAN
E003NAMAN

Now  Execute following query :-

    SELECT EmpId, EmpName,
    ROW_NUMBER()OVER(Partition by EMPID ORDER by EMPID) RowId  
    FROM M_Emp


Output :-
EmpId EmpNameRowId
E001GAGAN1
E001GAGAN2
E001GAGAN3
E002AMAN1
E002AMAN2
E003NAMAN1

This will results in the ranking of rows on the basis of column information.
I hope you understand the logic/syntax behind. basically It is used to perform any rank based operation.

Comments

Popular posts from this blog

FastEndpoint vs Minimal APIs vs Controller

Kick start 2021 😃😃

Work with Raspberry PI Zero W