Row Number to give same value when same partition

82 Views Asked by At

How to get the row number equal when the name is the same in the SELECT statement?

When I try with following code:

SELECT
    ROW_NUMBER() OVER (PARTITION BY BENFNAME ORDER BY BENFNAME DESC, BENFNAME DESC) AS ROWNUM
    , BENFNAME, BENLNAME
    , REMID, BENENATIONALITY 
    , CUSBENRELATION
FROM  SEND    
WHERE REMID = 445231

enter image description here

I need MEHARUN with the same row number, i.e. if any same name exit it should be in same row number.

Expected results:

enter image description here

1

There are 1 best solutions below

0
Jim Macaulay On

Use Dense Rank instead of Row Number,

SELECT
    DENSE_RANK() OVER (PARTITION BY BENFNAME ORDER BY BENFNAME DESC, BENFNAME DESC) AS ROWNUM
    , BENFNAME, BENLNAME
    , REMID, BENENATIONALITY 
    , CUSBENRELATION
FROM  SEND    
WHERE REMID = 445231