1

I have one table name called "ABC".

"ABC" Table format :

Operation   Status    value
----------------------------
OP10          1        100
OP10          1        200
OP10          2        300
OP20          1        400
OP20          3        500
OP30          1        100
OP30          2        200

I need to generate serial number for based on Operation.

E.g: Expected Output

SNo   Operation   Status    Value
-----------------------------------
1      OP10          1        100
1      OP10          1        200
1      OP10          2        300
2      OP20          1        400
2      OP20          3        500
3      OP30          1        100
3      OP30          2        200

How to get the result as above formatted output.

1 Answer 1

1

You can use DENSE_RANK()

SELECT DENSE_RANK() OVER (ORDER BY Operation) SNo,
       Operation, Status, Value
FROM yourTable
ORDER BY Value

Output:

enter image description here

Demo here:

Rextester

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.