7.2 结构化数据排序
1. 单字段排序
2. 多字段排序
3. 排序后的位置
4. 随机排序
SPL
A | B | |
---|---|---|
1 | =file(“EMPLOYEE.csv”).import@tc() | |
2 | =A1.sort(BIRTHDAY) | / 按生日升序排序 |
3 | =A1.sort([BIRTHDAY,-HIREDATE]) | / 按生日升序、入职日期降序排序 |
4 | =A1.psort@z(SALARY) | / 工资降序排序后的位置 |
5 | =A1.sort(rand()) | / 随机排序 |
SQL
1. 单字段排序
SELECT *
FROM EMPLOYEE
ORDER BY BIRTHDAY;
2. 多字段排序
SELECT *
FROM EMPLOYEE
ORDER BY BIRTHDAY ASC,HIREDATE DESC;
3. 排序后的位置
SELECT rn,SALARY
FROM(SELECT EMP.*,ROWNUM AS rn
FROM (SELECT * FROM EMPLOYEE ORDER BY EID) EMP)
ORDER BY SALARY DESC;
4. 随机排序
SELECT *
FROM EMPLOYEE
ORDER BY dbms_random.value;
Python
df = pd.read_csv('../EMPLOYEE.csv')
#按生日升序排序
sorted_by_birthday = df.sort_values('BIRTHDAY')
#按生日升序、入职日期降序排序
sorted_by_birthday_hiredate = df.sort_values(['BIRTHDAY', 'HIREDATE'], ascending=[True, False])
#工资降序排序后的位置
sorted_positions = np.argsort(-df['SALARY'].values)
#随机排序
random_sorted = df.sample(frac=1, random_state=42)