对 table 单行的 2 组不同值进行排序

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

我有以下 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

我必须根据 C 列对条目进行排序,该列的排序顺序应该是这样的, 15

32

45

0008 – 0030

0031 – 0059

0060 – 0090

请指教。提前致谢。

甲骨文SQL:

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

如果table有很多行并且查询会被频繁执行那么你应该添加这个索引:

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

如果您使用例如MSSQL 数据库然后用 CASE 语句替换 DECODE,用 CHARINDEX 替换 INSTR。