[英]Query in sql server to sort data which has both numbers and alphabets
[英]Sort String column which has numbers and Alphabets( 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
任何建議都會有很大幫助
如果您的第一順序子句確保主要排序順序基於UoA字段的數字部分,那么您的第二順序子句實際上可能只是UoA字段本身。 即
order by
regexp_substr(UoA, '^\D*'), UoA;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.