7.1 序列排序

 

6.3 定位计算


1. 升序排序

2. 降序排序

3. 排序后的位置

4. 随机排序

SPL

A B
1 [13,30,45,23,42,98,61]
2 =A1.sort() [13,23,30,42,45,61,98]
3 =A1.sort@z() [98,61,45,42,30,23,13]
4 =A1.psort() [1,4,2,5,3,7,6]
5 =A1.sort(rand()) [30,13,98,45,42,23,61]

SQL

1. 升序排序

SELECT *
FROM TABLE(sys.odcinumberlist(13,30,45,23,42,98,61))
ORDER BY COLUMN_VALUE;

2. 降序排序

SELECT *
FROM TABLE(sys.odcinumberlist(13,30,45,23,42,98,61))
ORDER BY COLUMN_VALUE DESC;

3. 排序后的位置

SELECT rn FROM(
    SELECT seq.*,ROWNUM AS rn
    FROM TABLE(sys.odcinumberlist(13,30,45,23,42,98,61)) seq)
ORDER BY COLUMN_VALUE;

4. 随机排序

SELECT *
FROM TABLE(sys.odcinumberlist(13,30,45,23,42,98,61))
ORDER BY dbms_random.value;

Python

seq = np.array([13, 30, 45, 23, 42, 98, 61]) 
seq_sorted_ascending = np.sort(seq)        #[13,23,30,42,45,61,98]
seq_sorted_descending = np.sort(seq)[::-1] #[98,61,45,42,30,23,13]
sorted_positions = np.argsort(seq)         #[0 3 1 4 2 6 5]
seq_random = np.random.permutation(seq)    #[61 45 98 13 23 42 30]

7.2 结构化数据排序
SPL SQL Python 代码示例对比