1.一般排序 , 并加序号
根据sal 升序,并加序号.
SQL> select rank()over(order by sal desc),name,sal from t1;
RANK()OVER(ORDERBYSALDESC) NAME SAL
-------------------------- -------------------- ----------
1 vv 3900
2 破破 3600
3 Lucy 3500
3 丽丽 3500
5 卡卡 3400
6 DS 3200
7 豆豆 3000
2.分组排序 , 并加序号
row_number() over (partition by *** order by *** desc ) as
SQL> select row_number() over (partition by comm order by sal desc ) as rank,name,sal,comm from t1;
RANK NAME SAL COMM
---------- -------------------- ---------- ----------
1 木头 4900 2000
2 Lucy 3500 2000
3 dop 3000 2000
4 dsod 2900 2000
5 HKL 2200 2000
1 vv 3900 4500
2 破破 3600 4500
3 丽丽 3500 4500
4 卡卡 3400 4500
5 DS 3200 4500
6 豆豆 3000 4500