Skip to content
Advertisement

SQL query to sort data while insert , first numbers then alphabets an last symbols

I am getting trouble to write SQL sort Query, I have table as follows

enter image description here

And I want to sort above data as, First should number and then alphabets and last special symbols like following table.

First numbers should sort like 1,2,3,11,22,33 then Alphabets should sort like a ,b,c,..z and then symbols, like following table

enter image description here

I have tried many ways but still not getting correct way, please help me to write query.

Advertisement

Answer

You can use a CASE WHEN on the ORDER BY to create some groups:

demo on dbfiddle.uk

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement