sql - Sorting of 2 different sets of values of single row of a table -


i have below table,

a             b            c --------   ----------     ----------- akhil      kerala         0008 – 0030 athul      kerala         15 basil      delhi          0031 – 0059 rahul      chennai        32 kishore    new york       0060 – 0090 anoop      mumbai         45 

i have sort entries according column c, sorted order of column should like, 15

32

45

0008 – 0030

0031 – 0059

0060 – 0090

kindly advice. in advance.

oracle sql:

select t.*,    to_number(decode(instr(c,' '),5,null,c)) atr1,   decode(instr(c,' '),5,c,null) atr2 test_tab t order atr1, atr2 

if table has many rows , query executed should add index:

create index sort_idx on test_tab (   to_number(decode(instr(c,' '),5,null,c)),   decode(instr(c,' '),5,c,null) ); 

if use e.g. mssql database replace decode case statement , instr charindex.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -