7.4 Rank the structured data
1. Single-field ranking
2. Multi-field ranking
SPL
A | B | |
---|---|---|
1 | =file(“EMPLOYEE.csv”).import@tc() | |
2 | =A1.ranks(BIRTHDAY) | /Rank by birthday in ascending order |
3 | =A1.ranks([BIRTHDAY,-HIREDATE]) | /Rank by birthday in ascending order and by hire date in descending order |
SQL
1. Single-field ranking
SELECT RANK() OVER (ORDER BY BIRTHDAY) AS rank
FROM EMPLOYEE
ORDER BY ROWNUM;
2. Multi-field ranking
SELECT RANK() OVER (ORDER BY BIRTHDAY ASC,HIREDATE DESC) AS rank
FROM (SELECT * FROM EMPLOYEE ORDER BY EID)
ORDER BY ROWNUM;
Python
df = pd.read_csv('../EMPLOYEE.csv')
#Rank by birthday in ascending order
birthday_ascending_rank = df['BIRTHDAY'].rank(ascending=True,method='min').values
Python doesn’t support multi-field ranking, so it has to hard code to do this calculation.
7.5 Transpose
Example codes for comparing SPL, SQL, and Python
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL