棘手的 sql 排序

tricky sql Ordering

我在 oracle 11g 上有一个 table,看起来像这样

col_1 |   col_2   |  col_3 |
1     | 111222001 |   A
2     | 111222001 |   B
3     | 111222002 |   A
4     | 111222002 |   B
5     | 111555001 |   B
6     | 111555003 |   A
7     | 111555003 |   B

我想订购,得到这个

col_1 |   col_2   |  col_3 |
2     | 111222001 |   B
4     | 111222002 |   B
1     | 111222001 |   A
3     | 111222002 |   A
5     | 111555001 |   B
7     | 111555003 |   B
6     | 111555003 |   A

背后的逻辑:

注意 col_2 值是三个三元组 111-222-333 的值。

我想按照第三个三元组111-222-"333"排序col_2,先只得到col_3 = 'B'的条目,然后得到那些有 col_3 = 'A' 的。 当第二个三元组(变化/上升)111-“222”-333 我们重做之前描述的内容。

在此先感谢,我想出了一个办法,但是真的很难看,如果有人能想出办法做得漂亮的话

Select * 
from table
order by col_3 desc, col2, col1;

您好,不知道为什么没看到,其实很简单,给您添麻烦了

select col_1、col_2、col_3 来自 table_name 按 substr(col_2,3,8), col_3, substr(col_2,9,11);

排序