Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How below column transform into double column with ascending group(sql)

I try to get this in single query but failed.
Do we need to use group set?

colA
200
400
300
500
200

transform into

colA colB
200 1
300 2
300 2
400 3
500 4

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Maybe use DENSE_RANK() windowing function if available in your SQL database

like

select ColA, 
DENSE_RANK() OVER( order by ColA) as colB
from yourtable
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading