sql - 排序具有数字和字母的字符串列(Oracle SQL)
问题描述
我想对可以同时包含数字和字母的字符串列进行排序。
SQL 脚本:
select distinct a.UoA, b.rating , b.tot from omt_source a left join
wlm_progress_Scored b
on a.UoA = b.UoA
where a.UoA in (select UoA from UserAccess_dev
where trim(App_User) = lower(:APP_USER))
order by
regexp_substr(UoA, '^\D*') ,
to_number(regexp_substr(UoA, '\d+'))--);
我目前得到的输出:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
23
26B
26A
27
28
30
31
32
33
34B
34A
但是,我想要26
并且34
按照这个顺序
26A
26B
34A
34B
任何建议都会很有帮助谢谢
解决方案
如果您的第一个 order by 子句确保主要排序顺序基于 UoA 字段的数字组件,那么您的第二个 order 子句实际上可能只是 UoA 字段本身。IE
order by
regexp_substr(UoA, '^\D*'), UoA;
推荐阅读
- matlab - 在 MATLAB 中使用 parfor 对数组进行间接索引
- java - How to split the string using Pattern/Matcher with multiple occurrences of pattern?
- dask - Loading Cassandra Data into Dask Dataframe
- r - R add column to match another dataframe
- python - Python-Generating numbers according to a corellation matrix
- android - getGeofenceTransition() 在将 ResultReceiver 作为 Intent 额外传递时返回 -1
- java - 如何使用硒在谷歌浏览器中获取网络文件?
- android - Notify activity from adapter when item is deleted (emptyView)
- c++ - 为什么我不能在一个类的不同行中声明和定义一个成员变量?
- python-3.x - abc() 接受 33 个位置参数,但给出了 35 个